This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Downloading from JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Downloading from JSP" Watch "Downloading from JSP" New topic
Author

Downloading from JSP

Raj Sethi
Greenhorn

Joined: Mar 11, 2001
Posts: 9
Hi All,
I got it working able to download a text file from JSP page..My problem is :
when the download box pops up (Save/Open),it has got following funny lines..
--
You have choosen to download from this location submit.jsp(name of the jsp file) <url>
--
Instead of the jsp file name(submit.jsp) I want it to display the name of downloaded text file..
I using following setting thanks to prevous postes messages..
<%@ page contentType="application/octet-stream" buffer="216k" autoFlush="true" %>
response.setHeader("Content-Disposition","attachment;filename=\"BoralInvoice.txt\"");
Any help is highly appreciated
Raj
Smita Tyagi
Greenhorn

Joined: May 09, 2001
Posts: 21
Hello Raj,
I am sorry that I am not helping you in any way but I want to ask you how have you downloaded txt file using JSP?
Thanks in advance
Smita
Sandeep Jain
Ranch Hand

Joined: Oct 25, 2000
Posts: 124
Hello Raj,
U can use the following code . I tried it in netscape and iexplorer .it works fine . I would like to just point out the thing that if it(browser) is not able to find the text file it will open the jsp file .

------------------
Sandeep Jain


Try and Try Till u succeed<br /> <br />Sandeep Jain
Sandeep Jain
Ranch Hand

Joined: Oct 25, 2000
Posts: 124
I am sorry ,I forgot to paste the code
<html>
<%@ page contentType="multipart/x-zip" autoFlush="true" %>
<% response.setHeader("Pragma","no-cache"); %>
<% response.setHeader("Expires", "0"); %>
<% response.setHeader("Content-Disposition", "attachment;filename=\"BoralInvoice.txt\""); %>
</html>

------------------
Sandeep Jain
Raj Sethi
Greenhorn

Joined: Mar 11, 2001
Posts: 9
Hi Thanks for your help..I tried your code it is the same ,may be I think my question was not clear ..
In my jsp page for downloading I'm NOT reading from any existing file,it dynamically generates data and WRITES to out object..
I think your code might work if it has to read from a file and write to out object ..corrrect me if I'm wrong .
could you pls. explain what is the purpose of using "pragma","expires" in header ..
Thanks again
Raj
David Qiu
Greenhorn

Joined: May 14, 2001
Posts: 8
Hi Sandeep thank you for your code
but when i used your code to download a resource, the dialog box showed it would download the jsp file, and as i press 'ok', the "save as" dialog box just showed the resource i required to download. the problem is that after do the download, the saved files are of the same size, 29 bytes. i wonder why this happened.
and i use tomcat4 and ie5. thanks again
 
jQuery in Action, 2nd edition
 
subject: Downloading from JSP
 
Similar Threads
Help Need- How Input parameter store in DB through Java Bean
session.getAttribute?
struts-config.xml:default for action tag input attribute
"Page can't be found" error after hit "submit"
JSF Newbie