try to add this to teh JSP:
<meta content="application/octet
and please let me know if it worked or not,
Nushi.
Main Topics
Browse All TopicsIn a JSP page of my site I am showing the .csv file links. When user clicks the link the file download dialog box use to appear to let the user download the file. This was working fine with IE 5.5. But user have shifted their browser version from IE5.5 to IE6.0. And now user do not see the same old download dialog box. The .csv file is getting open in the browser itself. Can anybody help me out? Because the same code was working with IE5.5 but it is not working with IE6.0. What may be the reason behind this?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
>> and then how will you open it?
Using a package that can deal with comma separated values.
Excel would still open the file. You just need to do "File | Open..." and then select it. Changing "data.csv" to "data.cs1" doesn't change the content.
Trying to set the content type of the page won't make any difference. It's not the page that is being loaded by the browser, it is the file that has been selected.
well instead of giving them the link of the csv file you can do the following...
give the link to a jsp/servlet....
set the response type to application/octet-stream.
open the file input stream to your csv file and read the contents in a stream..
put this stream down to the response stream....
This way Client system will always open up a download window regardless of browser type.
one more thing... if you do it in above specified manner you don't run into a situation where a user can type in the csv file url in the browser directly and can gain access to it ( security u know...:-))
furthermore you will be controling the whole download operation...
hope this helps.
Regards
use a force download servlet:
import java.io.*;
import javax.servlet.ServletExcep
import javax.servlet.http.HttpSer
import javax.servlet.http.HttpSer
import javax.servlet.http.HttpSer
public final class DownloadServlet extends HttpServlet {
private static final String basePath = "/doc";
public void service(HttpServletRequest
throws ServletException, java.io.IOException
{
String filePath = request.getPathInfo();
String filename = request.getParameter( "filename" );
if( filePath == null && filename != null ) filePath = "/" + filename;
if( filename == null ) filename = filePath;
if( filename != null ) filename = (new File(filename)).getName();
if( filePath != null ) {
InputStream in = null;
OutputStream out = null;
try {
in = getServletContext().getRes
if( in != null ) {
out = new BufferedOutputStream( response.getOutputStream()
in = new BufferedInputStream( in );
String contentType = "application/unknow";
System.out.println( "contentType: " + contentType );
response.setHeader("Conten
int c; while( ( c=in.read() ) != -1 ) out.write( c );
return;
}
} finally {
if( in != null ) try { in.close(); } catch( Exception e ) {}
if( out != null ) try { out.close(); } catch( Exception e ) {}
}
}
response.sendError( HttpServletResponse.SC_NOT
}
}
I didn't convert, I was the code I posted on another Q and thought this might save asker some effort of reinvent the wheel. :-)
http://www.experts-exchang
Hi there
I have wrriten one test jsp for doing the same. I suppose it is similar to what kennethxu
has suggested. Here is the code that i am using
this for jsp
<%@ page language="java" import="java.io.*"%>
<%
//
String filePath="";
String fileNameNew="test.csv";
filePath="/testing/"+fileN
response.setContentType("a
or
response.setContentType("a
response.addHeader("Conten
try{
File uFile= new File(filePath);
int fSize=(int)uFile.length();
FileInputStream fis = new FileInputStream(uFile);
PrintWriter pw = response.getWriter();
int c=-1;
// Loop to read and write bytes.
//pw.print("Test");
while ((c = fis.read()) != -1){
pw.print((char)c);
}
// Close output and input resources.
fis.close();
pw.flush();
pw=null;
}catch(Exception e){
}
%>
I have written one html to call the above jsp
<html>
<head>
<title> new document </title>
</head>
<body>
<br><br><br>
<center>
<br><br><br>
<br><br><br>
<a href="javaScript:openErr('
</center>
<form name="downloadFrm" action="" method="post">
<INPUT TYPE="hidden" name="fileName">
</form>
</body>
</html>
<SCRIPT LANGUAGE="JavaScript">
function openErr(file){
//alert("file "+file);
window.document.downloadFr
toOpen(file);
//window.document.download
//window.document.download
//window.document.download
}
winName="downloadWin";
var windowParams="toolbar=no,l
function toOpen(file) {
win1 = window.open("", winName, windowParams);
window.document.downloadFr
window.document.downloadFr
window.document.downloadFr
window.document.downloadFr
window.setTimeout('toClose
}
function toCloseWin(){
win1.close();
}
</SCRIPT>
This works in IE 6.0 SP1 very fine. But giving some error in IE5.5
In IE5.5 SP1 when the file download dialog box opens i select the
second option that is save file to the disk. but the file is not at all
saving. If i select the first option in file download box that is
open the file from current location then once again the file download
dialog box appears and then when i select the second option the file
save as dialog box appears. What may be the cause?
And one more query-
I have metioned the Timeout for child window to close.
but if user do not save the file to the disk and after 5 seconds
he clicks cancel then that child window remains there only.
In both the browsers situation is same. How can I make sure to close
the child?
And thanks a lot to all of you for suggesting me the various ways.
I would try
<a target="_blank" href="/testing/downloadTes
and see if this works for both IE5 and 6.
BTW, I have seen a lot of people reporting problem with jsp download. JSP is not designed for such tasks according to the specification. Please NOTICE that there was a line missing in above posted servlet:
response.setContentType(co
glad to know you problem is resolved. just for your future reference, there is a split points link right above comment area that can be used if comments from multiple excepts contributes to the final solution :-)
Kuldeepchaturvedi, please get your points here:
http://www.experts-exchang
Business Accounts
Answer for Membership
by: NushiPosted on 2004-01-06 at 02:04:32ID: 10050958
Hi there.
its beacuse that IE6 as an ActiveX instaled which know how to open/handle Excel files.
i will look into it im more details now.
Nushi.