aspose file tools*
The moose likes Servlets and the fly likes Problem with RequestDispatcher Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem with RequestDispatcher" Watch "Problem with RequestDispatcher" New topic
Author

Problem with RequestDispatcher

Prasad Babu
Ranch Hand

Joined: Jul 17, 2005
Posts: 57
Hi All,

See my servlet code.



While i am running the servlet, its telling that "cannot forword response/forward already coommited"

What is exact problem. I am creating RequestDispatcher when the condition is true only. if the first condition is true, the controller will go to the resource specified in the path. so no way to excute the remaining servlet. but its excuting. thats why its coming like that.(I think)

when i include return statement immediatly after forward method calling, its working fine. why its so.

please give the solution

thanks in advance.
Prasad
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

This is a common issue.

The response.forward method does not halt execution of your servlet; neither does response.sendRedirect.

You need to either branch your code in such a way that no code is run after a forward or always add a return statement just after the call to forward.


[ December 16, 2005: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem with RequestDispatcher