The filename set in the response.setHeader("Content-Disposition", "attachment; filename=test.csv") i

E

Ed

I'm trying to export my results to .csv file named test.csv. The
following is the code which I have in my .jsp file named testCSV.jsp:


response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;
filename=test.csv");

There are one major problem which I'm facing:
1. The File Download box comes up and when I click on the Save button,
the filename showing up is testCSV.jsp.

My question is: Which code, should I add in the testCSV.jsp to force
the File Download box to save the file as test.csv?

Thanks!
 
D

Daniel Pitts

Ed said:
I'm trying to export my results to .csv file named test.csv. The
following is the code which I have in my .jsp file named testCSV.jsp:


response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;
filename=test.csv");

There are one major problem which I'm facing:
1. The File Download box comes up and when I click on the Save button,
the filename showing up is testCSV.jsp.

My question is: Which code, should I add in the testCSV.jsp to force
the File Download box to save the file as test.csv?

Thanks!

If you map the URL (probably in your web.xml file, or if your using
spring, in your application context file) /test.csv to render using
your JSP.That way, the URL will look like www.mydomain.com/test.csv
 
T

Tim B

Ed said:
I'm trying to export my results to .csv file named test.csv. The
following is the code which I have in my .jsp file named testCSV.jsp:


response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;
filename=test.csv");

There are one major problem which I'm facing:
1. The File Download box comes up and when I click on the Save button,
the filename showing up is testCSV.jsp.

My question is: Which code, should I add in the testCSV.jsp to force
the File Download box to save the file as test.csv?

Thanks!

Your code above works for me, both in a jsp and (where it should really be)
in a servlet.Are you perhaps doing something unusual with the sequence of
events, like calling out.flush() before setting the header and content type?
 
E

Ed

Tim said:
Your code above works for me, both in a jsp and (where it should really be)
in a servlet.Are you perhaps doing something unusual with the sequence of
events, like calling out.flush() before setting the header and content type?

Hi Tim,

I have it working too, but it's failing when testCSV.jsp works as a
popup window.
It means when clicking the button which is in my other .jsp page(
parent.jsp), it will popup a jsp page which is testCSV.jsp.

And when the File Download box comes up, the filename showing up to be
saved or opened is: testCSV.jsp. It should be test.csv, as It is
included in the setHeader, as you see above!

For your info, out.flush is being called at the end of the jsp.

Very challenging question! I looked around on the internet, I didn't
see any answer, when the .jsp page used to display the csv report,
works as popup window!

Thanks!
 
E

Ed

Daniel said:
If you map the URL (probably in your web.xml file, or if your using
spring, in your application context file) /test.csv to render using
your JSP.That way, the URL will look like www.mydomain.com/test.csv

Hi Daniel,

I think that can be done, but when you have all kind of reports not
only csv reports but pdf report, it becomes difficult doing mapping, as
it's on my case!

I believe there is an answer to my problem, hopelly, I will resolve it.
Thanks!
 
E

Ed

Ed said:
Hi Tim,

I have it working too, but it's failing when testCSV.jsp works as a
popup window.
It means when clicking the button which is in my other .jsp page(
parent.jsp), it will popup a jsp page which is testCSV.jsp.

And when the File Download box comes up, the filename showing up to be
saved or opened is: testCSV.jsp. It should be test.csv, as It is
included in the setHeader, as you see above!

For your info, out.flush is being called at the end of the jsp.

Very challenging question! I looked around on the internet, I didn't
see any answer, when the .jsp page used to display the csv report,
works as popup window!

Thanks!

I am thinking too, that there may be something, I should add to my xsl
sylesheet! But I don't know!
 
T

Tim B

Ed said:
type?

Hi Tim,

I have it working too, but it's failing when testCSV.jsp works as a
popup window.
It means when clicking the button which is in my other .jsp page(
parent.jsp), it will popup a jsp page which is testCSV.jsp.

And when the File Download box comes up, the filename showing up to be
saved or opened is: testCSV.jsp. It should be test.csv, as It is
included in the setHeader, as you see above!

For your info, out.flush is being called at the end of the jsp.

Very challenging question! I looked around on the internet, I didn't
see any answer, when the .jsp page used to display the csv report,
works as popup window!

Thanks!
The only way I can replicate the error is to do an explicit flush() in the
jsp before writing the header info. I am testing on oc4j in jdeveloper. But
I don't know why you are displaying testCVS.jsp rather than using a servlet
and no popup.
 
B

BeGreen

Hi Tim,
The only way I can replicate the error is to do an explicit flush() in the
jsp before writing the header info.

This is good to know!

I am testing on oc4j in jdeveloper. But
I don't know why you are displaying testCVS.jsp rather than using a servlet
and no popup.

It's an out of the box Application, I am customizing. In the
testCVS.jsp, there are codes which call a servlet to do all the work of
retrieving data from the database.

I wish I could do it without the testCVS.jsp working as a popup, but I
don't have any choice, it's an out of the box application.

I believe there may be some code which need to be added to the XSL
Stylesheet's header to be used to append the extension such as .csv, or
..pdf to the header name, so that the File Download can show at least a
url with a .csv extesion, but I don't know!

Thanks for all your help!
 
E

Ed

Tim said:
The only way I can replicate the error is to do an explicit flush() in the
jsp before writing the header info. I am testing on oc4j in jdeveloper. But
I don't know why you are displaying testCVS.jsp rather than using a servlet
and no popup.

Tim,

Inside the testCVS.jsp, there are some codes to call a servlet used to
retrieve data from the database.

The problem is that It's an out of the box application, so testCVS.jsp
will always popup when I click ok on the dropdown button, to select its
url, in the Parent.jsp page.

I think I told you, I did use a no popup sample jsp page, in which I
put my servlet code, everything worked fine! The File Download box
showed the CSV filename and I downloaded it.

Very interesting and challenging issue, in my opinion, hope I resolve
it soon!
 
Joined
Sep 29, 2009
Messages
1
Reaction score
0
facing the same issue with inline option

Hi

We are opening the report generated as a pdf using JasperReports in the browser. We would like the pdf to have the file name that we set but the filename set in "response.setHeader("Content-disposition", "inline; filename=\"" + reportName + ".pdf\""); is being ignored. If I use "attachment" instead of "inline", the filename is getting set properly. However, in case of attachment option, a popup comes up. The popup is not desirable to the user. So, we would like to find out a way to set the filename correctly with the "inline" option. We are using IE 8. Please advise how we can open the generated pdf in the browser with the desired file name. Any help will be appreciated.

Thanks,
Runu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top