Hi, I am not able to forward the request to another Web Application running on my tomcat server. I am facing one problem related to ServletContext's getContext() method and getting NullPointerException. chapter02Context at line number 3 is null.
Here is the brief description I am trying to run this servlet on jakarta-tomcat-5.0.30. I have two web applications "chapter02" and "chapter04" and I am trying to forward the request from web application "chapter04" to "chapter02" index.html page using above code.
In jakarta-tomcat-5.0.30\conf\server.xml I have made these changes (refer line 1 and 2 below)..
Please let me know where I am making mitake, the correct format of string parameter of context.getContext(String URI). Because when I am trying to call context.getContext("/chapter02"), its returning null.
Hi, I tried both removing leading slash from getServletContext() and changing the properties "docbase" of context element in server.xml file, but nothing worked same error NullpointerException. The "chapter02Context" object is null, it means getServletContext is not working for across application.
It's allowed by specification to do not forward to other application. So some servlet containers will work, some won't. I'd suggest to use sendRedirect for more portable solution.
Tough in space?, <a href="http://tjws.sf.net" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="http://mediachest.sf.net" target="_blank" rel="nofollow">Check it here.</a><br /><a href="http://7bee.j2ee.us/book/Generics%20in%20JDK%201.5.html" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="http://7bee.j2ee.us/bee/index-bee.html" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="http://7bee.j2ee.us/addressbook/" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="http://searchdir.sourceforge.net/" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
As you are not getting the context of the application..you application is not initialized so all the further statements are of no use..frist try to make a proper web context and run a sample servlet..after that try with you full code..that would be a better idea when struck..if struck for making and defining a new context..just make a war file and put it in the webapps for self-deploy..that would create the context for you and with that you can try out your code..
Hi All, Thanks for your reply, I tried even making war file chapter02.war and chapter04.war and using the cross webapplication forward. But it did not work. I hope this is the problem with tomcat web server only, bacause specification says that its possible. Allthough sendRedirect("/chapter02/index.html") worked.
Hi Thanks Satou kurinosuke for your detailed explanation. I went through the URL provided you and I found that Tomcat this statment "Please note that for tomcat 5, unlike tomcat 4.x, it is NOT recommended to place <Context> elements directly in the server.xml file.". And this was the mistake I made. Now its working thanks.