Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with RequestDispatcher

 
Prasad Babu
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic