JSP页面怎么实现超链接定向绝对路径实现下载功能
现在我做了一个下载功能,超链接实现下载,但是貌似只能相对路径,绝对路径的不行,部分代码如下
页面超链接重定向:<a href="pages/download.jsp?fpath=/imgs/bg.jpg&fname=bg.jpg">xia</a>
下载页面:
<% response.setContentType("application/x-download");//设置为下载application/x-download
String fpath =(String)request.getParameter("fpath");
String fname =(String)request.getParameter("fname");
String filedownload =fpath;//即将下载的文件的相对路径
String filedisplay =fname;//下载文件时显示的文件保存名称
response.addHeader("Content-Disposition","attachment;filename=" + filedisplay);
try { RequestDispatcher dis = application.getRequestDispatcher(filedownload);
if(dis!= null) { dis.forward(request,response);
}
response.flushBuffer();
}
catch(Exception e)
{
e.printStackTrace();
}
finally { }
%>
但是我改成绝对路径就不行了,谁能帮我改下,实现绝对路径的下载
页面超链接重定向:<a href="pages/download.jsp?fpath=/imgs/bg.jpg&fname=bg.jpg">xia</a>
下载页面:
<% response.setContentType("application/x-download");//设置为下载application/x-download
String fpath =(String)request.getParameter("fpath");
String fname =(String)request.getParameter("fname");
String filedownload =fpath;//即将下载的文件的相对路径
String filedisplay =fname;//下载文件时显示的文件保存名称
response.addHeader("Content-Disposition","attachment;filename=" + filedisplay);
try { RequestDispatcher dis = application.getRequestDispatcher(filedownload);
if(dis!= null) { dis.forward(request,response);
}
response.flushBuffer();
}
catch(Exception e)
{
e.printStackTrace();
}
finally { }
%>
但是我改成绝对路径就不行了,谁能帮我改下,实现绝对路径的下载
...全文


Web 开发
