你要下载的东西都不在web application的目录中怎么直接用链接.
如果你要把需要下载的东西放在web application以外的目录中实现下载,可以在服务器端向客户端发送流的方式。
设置响应头:response.ContentType="application/octet-stream";
设定响应头内容:response.AddHeader("Content-Disposition","attahment;filename="+java.net.UrlEncoder.encode(filename,"UTF-8"));

解决方案 »

  1.   

    就是这样在页面中用超链接<a href="http://192.168.0.88:8080/c/jboss/bin/aaa.jar">实现下载但是当文件为.rar时用超链接<a href="http://192.168.0.88:8080/c/jboss/bin/aaa.rar">点击时可以出现下载框 但是下载总是不成功当文件为.jar时用超链接<a href="http://192.168.0.88:8080/c/jboss/bin/aaa.jar">点击时 则不出现下载框 
    我想下载.jar 文件 请问该如何解决?
      

  2.   

    如downfile.jsp<%@ page contentType="text/html;charset=big5"%>
    <%@ page language="java" import="java.io.*"%>
    <%!
    public String getStr(String str)
    {
      try{
        String temp_p=str;
        byte[] temp_t=temp_p.getBytes("ISO8859-1");
        String temp=new String(temp_t);
        return temp;
      }
      catch(Exception e){ e.printStackTrace();}
      return "";
    }
    %><%
    String szRoot=(String)session.getAttribute("rootpath"); //設定為你的目錄
    if (szRoot==null ||szRoot.equals(""))
        szRoot=application.getRealPath("/"); //取得根文件目錄String szSourceFile =getStr(request.getParameter("filename"));
    if(szSourceFile==null || szSourceFile.equals("")||szPath==null){
      response.sendRedirect("err.jsp");
      return;
    }String userpath=szRoot;//application.getRealPath("/");
    userpath= userpath  + "\\" + szSourceFile; //取得絕對路徑
    //System.out.println("DOWNLOAD FILE:" + userpath);try{
        InputStream inStream=new FileInputStream(userpath);
        response.reset();
        response.setContentType("bin");
        response.addHeader("Content-Disposition","attachment; filename=\"" + szSourceFile + "\"");
        byte[] b = new byte[100];
        int len;
        while((len=inStream.read(b)) >0)  response.getOutputStream().write(b,0,len);
        inStream.close();
    }
    catch(IOException e){
        System.out.println(e.getMessage());
    }
    %>應用:
    downfile.jsp?filename=xxxx