Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

page forwarding from servlets error

Status
Not open for further replies.

port1536

Programmer
Jan 31, 2003
2
GB
Hi

I have had a null pointer exception with this method in a servlet


private void gotoPage( String Address,
HttpServletRequest request,
HttpServletResponse response)

throws ServletException , IOException {
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(Address);
dispatcher.forward(request, response);
}



when used in the following scenario

page1 -> servlet1 -> page2 -> servlet2 ->{fails} back to page 2

I can forward ok from servlet1 to page2

servlet2 "hangs" in the browser and there is a null pointer exception
in the gotoPage method -.

are there any particular things which i need to set up to forward to any page for the second time?


java.lang.NullPointerException
at javax.servlet.GenericServlet.getServletContext(GenericServlet.java:205)
at orders.submitData.gotoPage(submitData.java:31)
at orders.submitData.performTask(submitData.java:321)
at orders.submitData.doGet(submitData.java:53)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:721)
at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:306)
at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:767)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:259)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:106)
at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:797)
at java.lang.Thread.run(Thread.java:484)
Process exited.


Any ideas on how I can find out what is causing the problem or fix it?

Second question : Is it better to have one servlet which controls all logic rather than two or more servlets - any comments gratefully appreciated

Many thanks








 
Are you sure that "Address" is not null ...

>>>> Second question : Is it better to have one servlet which controls all logic rather than two or more servlets - any comments gratefully appreciated
In my opinion, if you use multiple servlets and multiple JSP, you may as well just bin the servlets, and do everything in JSP - I mean, they get compiled to servlets anyway !
There is a big debate about this number of servlets/design model, JSP scriplets vs JSP tags etc.... in theory the MVC 2 pattern is really nice, but taken to extremes with frameworks like Struts can sometimes be massive overkill, if the application is not huge.

Take a look at :
for a "thumbs up MVC" take on things.
 
config was null - unsure if this was the problem and no time to investigate - any ideas anyone?



but used the following as a work around

response.sendRedirect("../page.jsp");








 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top