Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > The filename set in the response.setHeader("Content-Disposition", "attachment; filename=test.csv") is being ignored!

Reply
Thread Tools

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

 
 
Ed
Guest
Posts: n/a
 
      11-27-2006
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!

 
Reply With Quote
 
 
 
 
Daniel Pitts
Guest
Posts: n/a
 
      11-27-2006

Ed wrote:
> 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

 
Reply With Quote
 
 
 
 
Tim B
Guest
Posts: n/a
 
      11-27-2006

"Ed" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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?



 
Reply With Quote
 
Ed
Guest
Posts: n/a
 
      11-27-2006

Tim B wrote:
> "Ed" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
> > 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?


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!

 
Reply With Quote
 
Ed
Guest
Posts: n/a
 
      11-27-2006

Daniel Pitts wrote:
> Ed wrote:
> > 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


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!

 
Reply With Quote
 
Ed
Guest
Posts: n/a
 
      11-27-2006

Ed wrote:
> Tim B wrote:
> > "Ed" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed) oups.com...
> > > 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?

>
> 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!

 
Reply With Quote
 
Tim B
Guest
Posts: n/a
 
      11-28-2006

"Ed" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
>
> Tim B wrote:
> > "Ed" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed) oups.com...
> > > 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?
>
> 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.


 
Reply With Quote
 
BeGreen
Guest
Posts: n/a
 
      11-28-2006

Tim B wrote:
> "Ed" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) ups.com...
> >
> > Tim B wrote:
> > > "Ed" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed) oups.com...
> > > > 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?
> >
> > 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!


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!

 
Reply With Quote
 
Ed
Guest
Posts: n/a
 
      11-28-2006

Tim B wrote:
> "Ed" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) ups.com...
> >
> > Tim B wrote:
> > > "Ed" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed) oups.com...
> > > > 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?
> >
> > 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.


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!

 
Reply With Quote
 
rrathi rrathi is offline
Junior Member
Join Date: Sep 2009
Posts: 1
 
      09-29-2009
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: filename.gif or filename.gif.jpg? Bergamot HTML 0 05-30-2008 02:56 PM
Re: filename.gif or filename.gif.jpg? Beauregard T. Shagnasty HTML 1 05-30-2008 01:23 PM
Stitch rar files ( filename.part01 and filename.part02) Please help ixgor Software 1 10-15-2006 02:33 AM
how to get 8.3 format filename from long filename jacobyv@sis.unibe.ch Java 1 06-15-2006 10:39 AM
Extract filename from a filename typed by user =?Utf-8?B?Sm9l?= ASP .Net 1 08-23-2004 11:29 PM



Advertisments