aspose file tools*
The moose likes Tomcat and the fly likes ServletContext returns null on Tomcat? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "ServletContext returns null on Tomcat?" Watch "ServletContext returns null on Tomcat?" New topic
Author

ServletContext returns null on Tomcat?

Mark Stein
Ranch Hand

Joined: May 20, 2002
Posts: 75
Hi,

The basics... Apache 1.3x coupled to Tomcat 4.1 using mod_jk. Apache's httpd.conf is set up to send *.jsp and /servlet/* to tomcat. Tomcat has the context path set to "" (the default) and the doc path set to "public_html (WEB-INF is under public_html). Servlets are mapped "/servlet/servletname" Jsp's work fine, and so do simple servlets (both mapped, and using the invoker statement).

My problem is when I try to use a RequestDispatcher (both ServletContext, and HttpRequest). I've managed to track it down to the fact that Tomcat is returning null when I getServletContext(). It's not the code because it works on Resin.

My guess is it's either a Context path issue in server.xml, and/or a servlet mapping problem. I've tried setting the context path to "/" and that gives me a 500 error on tomcat. I've tried moving the webapp to a different dir and setting a new context path and that gives me a 404 error (using both mapping and invoker).

Anyone have any clues what's up?

Thanks
Mark Stein
Ranch Hand

Joined: May 20, 2002
Posts: 75
After much hair pulling, I managed to solve the problem, but I have no idea why... Maybe someone can explain it to me....

On both Tomcat 4.0 and Resin, getServletContext() gave me a servlet context. On Tomcat 4.1, I had to use getServletConfig().getServletContext().

Anyone ever hear of this before, or have any ideas?

Thx.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ServletContext returns null on Tomcat?
 
Similar Threads
strange instructions for servlet setup
Problems getting servlets to work on Tomcat 4
servlet mapping acting differently after deploying to server
HTTP Status 404 servlet error ("The requested resource is not available")
Configuring Tomcat 5 on Win2K and Linux