You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Corey Kaiser <co...@altrec.com> on 2006/04/27 02:17:41 UTC

JSPs, contexts, Tomcat 5.5.16+ and NPEs

I've finally nailed down what I think my problem with Tomcat 5.5.16 and
greater is, and condensed it into this easy-to-use, FunSize-ed post.

I have a webapp that is at the root of my appBase, defined in a Context
element in my server.xml, like so:

<Host name="www.mysite.com" appBase="/web/mysite" unpackWARs="true"
autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">

	<Context path="" docBase="" reloadable="true" crossContext="true">
		<Parameter name="propfile" value="myProps.properties"/>
	</Context>

</Host>

I have a servlet, myServlet, defined in my webapp's web.xml (which is
located on the filesystem at /web/mysite/WEB-INF/web.xml) and mapped to
/servlets/myServlet (accessible and working at
www.mysite.com/servlets/myServlet)

I have a JSP that lives on the filesystem at /web/mysite/myDir/myPage.jsp,
to be accessed at www.mysite.com/myDir/myPage.jsp and contains code similar
to this:

<% ServletContext ctx = pageContext.getServletContext().getContext("/");
	String myUrl = "/servlets/myServlet"; 
	RequestDispatcher dispatcher = ctx.getRequestDispatcher(myUrl); 
	dispatcher.include(request, response);
	out.clear();
	out = pageContext.pushBody(); %>

The global web.xml is untouched, and there's really only my servlet mappings
in the webapps web.xml.

With this config, the www.mysite.com/myDir/myPage.jsp works great on 5.5.15
and below.

On 5.5.16+ I get a NullPointerException, that alludes to the
RequestDispatcher line. I'm guessing that is because getServletContext() is
returning null rather than a root context, or something...

If I copy the myPage.jsp to the root (/web/mysite/myPage.jsp) on 5.5.16+, it
works fine.

 I have tried replacing the path="" with path="/" from the Context
definition and it's exactly the same. Same goes for removing the docBase="".
Changing the getContext("/") in the jsp to getContext("") produces the same
result, as does removing it and just using getServletContext().
The servlet doesn't appear to be the problem, as I can replace it with the
simplest of servlets and get the same problem.

I'm running Apache 1.3.34 with mod_jk 1.2.15, and the appropriate JkMounts,
workers, etc., oh and yes, I'm blocking access to WEB-INF and META-INF in my
Apache config. I know it's a bit wonky, but I'm trying to shoehorn an old,
large collection of servlets that run great on Apache + JServ into a Tomcat
configuration. This is the last little nagging problem.

Many thanks in advance for any help.
-corey

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: JSPs, contexts, Tomcat 5.5.16+ and NPEs

Posted by Marc Farrow <ma...@gmail.com>.
I don't have much to add, but I will try to give a suggestion or pointers
for you to research.  I just wanted to start off by saying (in my opinion)
this was an excellent post and it described the problem and situation very
clearly.

Have you tried getServletContext().getContext("/web/mysite")?

Also, since you are making this call in a JSP page, the current context is
the JSP servlet provided by Tomcat.  You are correct in trying to get a
foreign context.  I am not sure what IDE you use, but in NetBeans and also
in Eclipse in the past I was able to debug my Servlet/JSP and use watches,
etc to play with the code to get my RequestDispatcher to work properly.

HTH or at least points you in the right direction.

Marc



On 4/26/06, Corey Kaiser <co...@altrec.com> wrote:
>
> I've finally nailed down what I think my problem with Tomcat 5.5.16 and
> greater is, and condensed it into this easy-to-use, FunSize-ed post.
>
> I have a webapp that is at the root of my appBase, defined in a Context
> element in my server.xml, like so:
>
> <Host name="www.mysite.com" appBase="/web/mysite" unpackWARs="true"
> autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
>
>        <Context path="" docBase="" reloadable="true" crossContext="true">
>                <Parameter name="propfile" value="myProps.properties"/>
>        </Context>
>
> </Host>
>
> I have a servlet, myServlet, defined in my webapp's web.xml (which is
> located on the filesystem at /web/mysite/WEB-INF/web.xml) and mapped to
> /servlets/myServlet (accessible and working at
> www.mysite.com/servlets/myServlet)
>
> I have a JSP that lives on the filesystem at /web/mysite/myDir/myPage.jsp,
> to be accessed at www.mysite.com/myDir/myPage.jsp and contains code
> similar
> to this:
>
> <% ServletContext ctx = pageContext.getServletContext().getContext("/");
> >        String myUrl = "/servlets/myServlet";
> >        RequestDispatcher dispatcher = ctx.getRequestDispatcher(myUrl);
> >        dispatcher.include(request, response);
> >        out.clear();
> >        out = pageContext.pushBody(); %>
>
>
>
> The global web.xml is untouched, and there's really only my servlet
> mappings
> in the webapps web.xml.
>
> With this config, the www.mysite.com/myDir/myPage.jsp works great on
> 5.5.15
> and below.
>
> On 5.5.16+ I get a NullPointerException, that alludes to the
> RequestDispatcher line. I'm guessing that is because getServletContext()
> is
> returning null rather than a root context, or something...
>
> If I copy the myPage.jsp to the root (/web/mysite/myPage.jsp) on 5.5.16+,
> it
> works fine.
>
> I have tried replacing the path="" with path="/" from the Context
> definition and it's exactly the same. Same goes for removing the
> docBase="".
> Changing the getContext("/") in the jsp to getContext("") produces the
> same
> result, as does removing it and just using getServletContext().
> The servlet doesn't appear to be the problem, as I can replace it with the
> simplest of servlets and get the same problem.
>
> I'm running Apache 1.3.34 with mod_jk 1.2.15, and the appropriate
> JkMounts,
> workers, etc., oh and yes, I'm blocking access to WEB-INF and META-INF in
> my
> Apache config. I know it's a bit wonky, but I'm trying to shoehorn an old,
> large collection of servlets that run great on Apache + JServ into a
> Tomcat
> configuration. This is the last little nagging problem.
>
> Many thanks in advance for any help.
> -corey
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


--
Marc Farrow