aspose file tools*
The moose likes Servlets and the fly likes File download and request Forward Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "File download and request Forward" Watch "File download and request Forward" New topic
Author

File download and request Forward

Subha Garg
Ranch Hand

Joined: Feb 28, 2008
Posts: 39
Hello

I want to send a file to browser and then want to send control to another jsp.
i am sending a file to browser through following command which is opening in a new window.after that i want to forward the page to a jsp how can i do it

response.setContentType("application/doc");
response.setHeader("Content-Disposition", "attachment;filename=\""+ "FullElementReport"+ ".doc\";");
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You can only have one response per request.
You can't do both.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Subha Garg
Ranch Hand

Joined: Feb 28, 2008
Posts: 39
What other alternative do i have for the following situation:



on file1.jsp

i have a button with caption download file

on the click of the button request is submitted to downloadfile.java servlet

downloadfile.java servlet sends doc file to browser by opening separate (open ,save as) dialog box

during this event my file1.jsp is visible in its own window on client side while client gets an (open saveAs) popup dialog for doc file.

i want my downloadfile.java servlet to send the download file to servlet (which it is doing perfectally well) and also refresh the file1.jsp which i cannot do because servlet cannot send two responses?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

What I've done this case is turn it around.

I have the link point to the second JSP.
In the second JSP, I have a hidden iframe that has makes a request for the download file in its onload event.

One caveat: Some of our customers have started having trouble with this in MSIE6 when running without SSL, after one of the Windows updates installed a popup blocker that doesn't allow new windows to be opened from the onload event (even when the popup blocker is shut off). Our app always runs under SSL in production so I haven't had to find a solution for it but, if I had to, I would try using a refresh header instead of JavaScript from the onload event.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File download and request Forward