• 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
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

forwarding response from Servlet to Jsp

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How could you say "nothing is impossible"

I have done "nothing" in the past 24 hours....
And believe me "Its possible"
 
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May I ask why you want to have further jsp processing on that scenario?
 
Bunty Paul
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic