• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

foward() - problem in coding

 
Garlapati Ravi
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All



My question is : what about "str ----->>> " message which i was trying to print in Sample.java class. Where it has gone, when it is going to print?
What's wrong in my code which stopping this line to print.
session value i could able to fetch in Sample.java and able to print that on console. What about browser message(str ----->>> ). How to make this print on browser?
we all know that, control will come back to the source from where foward() was called. but why it's failing in this case ?

Regards,
Ravi
[ May 26, 2008: Message edited by: Garla Ravi ]
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because when a RequestDispatcher forward completes, the response is committed and closed by the container, so you cannot write any more content to the output buffer. If you still want to write content to the output, you should use an include rather than a forward.

This is vaguely similar to the use of <jsp:forward /> which was explained here.
 
Garlapati Ravi
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
committed and closed by the container

from the link you have provided, i understood one point, controller will never come back to the source servlet/JSP ? in that case how come "end of forward from Sample class :: " got printed from Sample.java servlet on server console and how it got session value which was set in target servlet ? please clarify.
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No - some slight confusion on your part there. Control does always return from the RequestDispatcher forward() invocation back into the servlet (it's impossible for a method invocation not to return under normal executing conditions). It is the response object (stream) which is committed and closed, not the entire executing thread! Hence you cannot write anything to the response object (since it is closed), but you can still write to the server logs/console (as the thread is still executing).

The link I gave is to a JSP issue which is related but subtly different: this talks about the <jsp:forward /> tag which actually does terminate execution of the JSP and return to the previously executing servlet (in that case).
 
Garlapati Ravi
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Clarrified ! Thank You very much.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic