• 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

Request Dispatcher-help needed

 
Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I m using RequestDispatcher like this,

A.jsp
-----
RequestDispatcher dis = getServletContext().getRequestDispatche("/myservlet?value=abc");

dis.forward(request,response);

i want to display a text message in A.jsp before forwarding.
how it is to be done?

Thanks
 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Basically you can't. from the api

forward should be called before the response has been committed to the client (before response body output has been flushed). If the response already has been committed, this method throws an IllegalStateException. Uncommitted output in the response buffer is automatically cleared before the forward.



What does this mean - if you send anything to the client it either causes the forward to throw an IllegalStateException if what you have sent has already made it to the client OR what you sent to the client is flushed from the buffer and so never makes it to the client.

So what can you do. The easiest thing is to return a page that displays the message and then, through a meta tag or another way (there are several), redirects the browser to the page that you wanted the client to go to.
Or as an alternative return a page that has the message you want to display and as it loads - via javascript it calls the servlet again which can then do a



HTH Mat
 
MInu
Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mat....
 
No matter. Try again. Fail again. Fail better. This time, do it with 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