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

Discussion in 'Java' started by Ed, Nov 27, 2006.

  1. Ed

    Ed Guest

    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!
    Ed, Nov 27, 2006
    #1
    1. Advertising

  2. Ed

    Daniel Pitts Guest

    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
    Daniel Pitts, Nov 27, 2006
    #2
    1. Advertising

  3. Ed

    Tim B Guest

    "Ed" <> wrote in message
    news:...
    > 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?
    Tim B, Nov 27, 2006
    #3
  4. Ed

    Ed Guest

    Tim B wrote:
    > "Ed" <> wrote in message
    > news:...
    > > 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!
    Ed, Nov 27, 2006
    #4
  5. Ed

    Ed Guest

    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!
    Ed, Nov 27, 2006
    #5
  6. Ed

    Ed Guest

    Ed wrote:
    > Tim B wrote:
    > > "Ed" <> wrote in message
    > > news:...
    > > > 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!
    Ed, Nov 27, 2006
    #6
  7. Ed

    Tim B Guest

    "Ed" <> wrote in message
    news:...
    >
    > Tim B wrote:
    > > "Ed" <> wrote in message
    > > news:...
    > > > 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 B, Nov 28, 2006
    #7
  8. Ed

    BeGreen Guest

    Tim B wrote:
    > "Ed" <> wrote in message
    > news:...
    > >
    > > Tim B wrote:
    > > > "Ed" <> wrote in message
    > > > news:...
    > > > > 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!
    BeGreen, Nov 28, 2006
    #8
  9. Ed

    Ed Guest

    Tim B wrote:
    > "Ed" <> wrote in message
    > news:...
    > >
    > > Tim B wrote:
    > > > "Ed" <> wrote in message
    > > > news:...
    > > > > 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!
    Ed, Nov 28, 2006
    #9
  10. Ed

    rrathi

    Joined:
    Sep 29, 2009
    Messages:
    1
    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
    rrathi, Sep 29, 2009
    #10
  11. Ed

    alok000707

    Joined:
    Jul 13, 2010
    Messages:
    1
    hi

    Use following code before setting any content or header to response.

    response.reset();
    alok000707, Jul 13, 2010
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. S.Kartikeyan

    Response.AddHeader content-disposition

    S.Kartikeyan, Feb 6, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    3,958
    S.Kartikeyan
    Feb 6, 2004
  2. Costas Andriotis
    Replies:
    0
    Views:
    1,137
    Costas Andriotis
    Oct 15, 2004
  3. =?Utf-8?B?SmVk?=

    Content-Disposition Doesn't Set Filename in IE

    =?Utf-8?B?SmVk?=, Apr 6, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    13,400
    =?Utf-8?B?SmVk?=
    Apr 8, 2005
  4. Arvind

    response.setHeader problem

    Arvind, Apr 23, 2004, in forum: Java
    Replies:
    7
    Views:
    4,600
    Arvind
    Apr 28, 2004
  5. YogeshWakchaure

    response.setHeader(lnline )is not working

    YogeshWakchaure, Apr 4, 2012, in forum: Java
    Replies:
    0
    Views:
    508
    YogeshWakchaure
    Apr 4, 2012
Loading...

Share This Page