<%@ page import= "java.io.* "%>
<%@ page contentType= "application/x-msdownload "%>
<%
String filename= request.getParameter( "url ");
FileInputStream fis=new FileInputStream(filename);
response.addHeader( "Content-Dispositon ", "ATTACHMENT;filename=hapuer.txt ");
ServletOutputStream sos=response.getOutputStream();
BufferedOutputStream bos=new BufferedOutputStream(sos);
byte[] buf=new byte[4096];
int len=fis.read(buf);
while(len!=1)
{
bos.write(buf,0,len);
bos.flush();
len=fis.read(buf);
}
fis.close();
bos.close();
%>
请问一下,我这里在filename中设置了一个值为hapuer.txt在下载的时候那个默认的文件名应该是hapuer.txt啊!可我在运行的时候,默认的文件名是:download.jsp 请问这是为什么呢?
------解决方案--------------------
你可以用转义字符
response.addHeader( "Content-Dispositon ", "ATTACHMENT;filename=\ "hapuer.txt\ " ");