/* download.jsp**/<%
try {

String url = "D:/aaaa.txt";//文件路径 可以用request.getParameter();取参数
String name = "aaaaaaaaaaaaaaaaaa";//显示给用户看的文件名,即ie弹出下载框中提示保存的文件名
response.reset();
response.setContentType("bin");
response.setHeader("Content-Disposition", "attachment; filename="+new String(name.getBytes(),"iso8859-1"));

ServletOutputStream os = response.getOutputStream();
FileInputStream in = new FileInputStream(url);
byte[] data = new byte[1024];
int temp = -1;
while((temp=in.read(data))!= -1){
os.write(data,0,temp);
os.flush();
}//while//

os.close();
} catch(Exception e) {
out.print(e.toString());
}
%>

解决方案 »

  1.   

    <script language="javascript">
    function confirmlink(link)
    {
      if (confirm("请确定连接下载"))
      {
        window.location = link;
        //或者window.open(link,"windowsName","scrollbars=yes,width=600,height=450");
    }
    </script>
    <a href="confirmlink('http://www.sina.com')">连接文字</a>
      

  2.   

    response.setHeader("content-disposition", "attachment;filename="+filename);
                             RandomAccessFile saveasout = new RandomAccessFile(fileName, "r");
                             byte[] line = new byte[ (int) saveasout.length()];
                             saveasout.read(line);
                             response.getOutputStream().write(line);
                             saveasout.close();
      

  3.   

    你们可能没太明白偶的意思,我的页面应该是这样的:
    aaaaaaaaaaaaaaaaaaa  连接a.zip
    bbbbbbbbbbbbbbbbbbb  连接b.word
    ....
    .....
    我现在是:右键---》另存为--》这样都好用的,我现在的问题是让用户直接点连接文字,弹出保存对话框,不点右键。该如何实现?
      

  4.   

    只有自己写个类了,download文件,中文有2种解决办法:
    1。用时间戳:每次文件UPLOAD后,文件改名,但这种方法比较土,呵呵
    2。自己写个转换的类,把汉字编码转一下,然后在转回去,即可,
    需要我发给你