Problem Writing to a CSV from a JSP behind a Security Constraint

Discussion in 'Java' started by Justin, Aug 8, 2003.

  1. Justin

    Justin Guest

    I am trying to write to a CSV for the user to download through my JSP.
    The following is the entire JSP test page (MyJsp.jsp) I created:

    <%
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition","attachment;
    filename=data.csv");
    out.println( "a,b,c" );
    out.println( "10,34,55" );
    %>

    When I run this file in IE6 from my project that has a security
    constraint set in the web.xml, the download window popups up and
    prompts the client to download. Saying the file name is MyJsp.jsp and
    the file type is blank. When I try and save or open the file I get the
    following error:

    "Internet Explorer cannot download MyJsp.jsp from localhost.
    Internet Explorer was not able to open this Internet site. The
    requested site is either unavailable or cannot be found. Please try
    again later."

    If I remove the security constraint it works fine, but I would need
    this process to run only for authenticated users. I have tried this on
    both Tomcat 4.1.24 and 5.0.3 and had the same results.

    Any help is greatly appreciated.

    Thanks,
    Justin Erickson
     
    Justin, Aug 8, 2003
    #1
    1. Advertising

  2. Justin

    Scott Yanoff Guest

    Justin wrote:

    > I am trying to write to a CSV for the user to download through my JSP.
    > The following is the entire JSP test page (MyJsp.jsp) I created:
    >
    > <%
    > response.setContentType("application/vnd.ms-excel");
    > response.setHeader("Content-Disposition","attachment;
    > filename=data.csv");
    > out.println( "a,b,c" );
    > out.println( "10,34,55" );
    > %>
    >
    > When I run this file in IE6 from my project that has a security
    > constraint set in the web.xml, the download window popups up and
    > prompts the client to download. Saying the file name is MyJsp.jsp and
    > the file type is blank. When I try and save or open the file I get the
    > following error:
    >
    > "Internet Explorer cannot download MyJsp.jsp from localhost.
    > Internet Explorer was not able to open this Internet site. The
    > requested site is either unavailable or cannot be found. Please try
    > again later."


    Here are a couple of things to try:
    1) Since it is a CSV file, try setting the content type to "text/csv".
    However, I am not sure if you then have to set the browser to use Excel
    for this type of document.

    2) Some versions of IE seemed to appreciate it if the URL ended with the
    extension of the file you are attempting to download/save. You can do
    this with a dummy parameter at the end of the URL. For example:
    your_url/someJsp.jsp?filename=data.csv
    So, it might help by making references to your JSP end with that dummy
    query string.

    Good luck,
    --
    -Scott
    | http://www.yanoff.org | AOL IM: SAY KJY
     
    Scott Yanoff, Aug 11, 2003
    #2
    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. Jack Fox
    Replies:
    3
    Views:
    483
    JIMCO Software
    Sep 11, 2005
  2. bootman
    Replies:
    0
    Views:
    568
    bootman
    Aug 11, 2003
  3. Replies:
    0
    Views:
    4,405
  4. puvit82
    Replies:
    4
    Views:
    763
    puvit82
    Feb 1, 2008
  5. harryos
    Replies:
    0
    Views:
    1,605
    harryos
    Nov 25, 2008
Loading...

Share This Page