aspose file tools*
The moose likes JSP and the fly likes forwarding response from Servlet to Jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "forwarding response from Servlet to Jsp" Watch "forwarding response from Servlet to Jsp" New topic
Author

forwarding response from Servlet to Jsp

Bunty Paul
Greenhorn

Joined: Jun 26, 2006
Posts: 28
I have a problem . I have a screen where when i press a button it goes to the servlet , and there i am constructing a rtf or pdf file , then writing to the output stream and closing it. But after that i want to go back to the same jsp and display some message .

response.setContentType("application/text");
response.setHeader("Content-Disposition",
"inline; filename=\"" + "test.pdf" +"\"");
response().setBufferSize(100*1024); //100KB

OutputStream fos;
fos = response().getOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(fos);
bos.write(data.toString().getBytes());
bos.flush();
bos.close();

after this i have to forward the response to jsp.

I get the exception : java.lang.IllegalStateException: Cannot forward after response has been committed

I am using struts framework.

I know a response cannot be forwarded to jsp after closing the stream

but still i want to acheive this requirement somehow.

is there any other way of doing it. i believe nothing is impossible
Manoj Paul
Ranch Hand

Joined: Jan 18, 2007
Posts: 110
How could you say "nothing is impossible"

I have done "nothing" in the past 24 hours....
And believe me "Its possible"
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2046
May I ask why you want to have further jsp processing on that scenario?
Bunty Paul
Greenhorn

Joined: Jun 26, 2006
Posts: 28
Originally posted by Jesus Angeles:
May I ask why you want to have further jsp processing on that scenario?


Thats the requirement for the project i am working on.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Can you please elaborate your requirement? Like what kind of message you want to display using a JSP page? And if its like that then why are you throwing the output to the user using response object in your first place?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

Guess what? It is impossible.

You cannot return two responses for one request.

What is possible is to forward to the JSP, and then using Javascript on the page, cause a request to a servlet to fetch the PDF.

Setting the content-disposition correctly (search through this forum for examples) will cause the JSP to remain displayed while the user is presented with the download dialog.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: forwarding response from Servlet to Jsp
 
Similar Threads
Cannot forward after response has been committed
Websphere 3.5 and Request Dispatcher (Part 2)
RequestDispatcher forward
Web App HashMap Serilization
Corrupt PDF Files