Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Apache Tomcat »

JSPs, contexts, Tomcat 5.5.16+ and NPEs

Corey Kaiser

2006-04-26

Replies:

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@(protected)
For additional commands, e-mail: users-help@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.