• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Writing to the output after forward

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,
i need help regarding some lines of code..

...
...(lines of code)
out.println("hi");
requestDispatcher view = request.getRequestDispatcher("biren.jsp");
view.forward(req,res);
out.println("biren");
...
...(more lines of code ending the servlet)

As far as i know..if the response is committed then we can not use the requestdispatcher to forward the request.

but if i have not commited the response with flush() method...and i m forwarding to a jsp or servlet ..then whether the output would contain my name biren?>>>
pleae help me out...

if the biren.jsp does not have any code that can be output..what will be the output.
 
Ranch Hand
Posts: 90
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
During my tests I had an exception when I printed something after forward (just because I forgot to add "return" after forwarding to my custom error page instead of desired View jsp).
 
Biren shah
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,.

i need some more explanations like..
if exception is there..than what kind of exceptions..
i dont think we need to write and return statement..
if we need to write..a return statement then ..what is the reasone for writing it.???

please forgive me for my typos
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

but if i have not commited the response with flush() method...and i m forwarding to a jsp or servlet ..then whether the output would contain my name biren?>>>
pleae help me out...

if the biren.jsp does not have any code that can be output..what will be the output.



when the forward method return to the calling servlet, at this stage the response is in commited state. After the calling of forward method, you can do the other processing , but it is not recommended so we put return immediately after it.

As the response is already commited (invalid) you can not view any contains in the browser generated after the forward method. If you use the out.println statement after forward method and the response is not closed , it throws the IllegalStateException, but it can not displayed in browser. You can check your log file.

If ypu put the statement.

log(response.isCommited()); after the forward statement, it shows tye value true.

Hope it help.

Thanks
 
Biren shah
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks narendra and all others..
i got it now..
thanks for the help
 
Ranch Hand
Posts: 55
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems logic.
 
Alas, poor Yorick, he knew this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic