permaculture playing cards*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Request Dispatcher-help needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Request Dispatcher-help needed" Watch "Request Dispatcher-help needed" New topic
Author

Request Dispatcher-help needed

MInu
Ranch Hand

Joined: Oct 09, 2003
Posts: 517
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


God Gave Me Nothing I Wanted<br />He Gave Me Everything I Needed<br /> - Swami Vivekananda
Mat Williams
Ranch Hand

Joined: Jul 20, 2005
Posts: 215
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

Joined: Oct 09, 2003
Posts: 517
Thanks Mat....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Request Dispatcher-help needed
 
Similar Threads
jsp:include page="header.html" causes IllegalStateException
Number of Instances
how to process response from here?
How to pass value to other page
Doubt in setAttribute() for Request object