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

J

Justin

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
 
S

Scott Yanoff

Justin said:
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,
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top