在页面中点击连接直接下载文件

response.setContentType("application/x-download");//设置为下载application/x-download
String filedownload =filepath;//即将下载的文件的相对路径
String filedisplay = filename;//下载文件时显示的文件保存名称
String filenamedisplay = URLEncoder.encode(filedisplay,"UTF-8");
response.addHeader("Content-Disposition","attachment;filename=" + filenamedisplay);
try
{
    RequestDispatcher dis = application.getRequestDispatcher(filedownload);
    if(dis!= null)
    {
        dis.forward(request,response);
    }
    response.flushBuffer();
}
catch(Exception e)
{
    e.printStackTrace();
}
finally
{   
}

 

 

用windows.open来调用这个页面

你可能感兴趣的:(windows)