下载页面
String lj = application.getRealPath("/")+"wireless/hw/tzhsy/";
File file = new File(lj+"tzhsymd.txt");
<a href="./bmmd.jsp?flag=dcmd" >导出所有选手名单</a><%if(show){ %> <a href="download.jsp?filename=tzhsymd.txt&filepath=<%=lj %>" >下载名单</a><%} %>
download.jsp
<%
String filename = request.getParameter("filename");//"tzhsymd.txt";
String filepath = request.getParameter("filepath");//"lj";
int i = 0;
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition","attachment;filename = "+filename);
java.io.FileInputStream fileInputStream = new java.io.FileInputStream(filepath+filename);
while((i= fileInputStream.read()) != -1){
out.write(i);
}
%>
可以下载文件保存,而不是直接打开txt