File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Request Dispatcher-help needed

Ranch Hand

Joined: Oct 09, 2003
Posts: 517
I m using RequestDispatcher like this,

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


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


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

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

Ranch Hand

Joined: Oct 09, 2003
Posts: 517
Thanks Mat....
I agree. Here's the link:
subject: Request Dispatcher-help needed
jQuery in Action, 3rd edition