This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem with RequestDispatcher" Watch "Problem with RequestDispatcher" New topic

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.
Ben Souther

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
I agree. Here's the link:
subject: Problem with RequestDispatcher
It's not a secret anymore!