JSP页面中,简单的文件下载~(weblogic&tomcat可用)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE></TITLE>
</head>
<body style="background-color:transparent">
<%
response.setContentType("application/x-download");
String filename = request.getParameter("filename1");
String filedownload = "/document/"+filename;
System.out.println("request "+request.getParameter("filename"));
String filedisplay = filename;
filedisplay = java.net.URLEncoder.encode(filedisplay,"UTF-8");
response.addHeader("Content-Disposition","attachment;filename=" + filedisplay);
try
{
RequestDispatcher dis = application.getRequestDispatcher(filedownload);
if(dis!= null)
{
dis.forward(request,response);
}
response.flushBuffer();
out.clear();
out = pageContext.pushBody();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
}
%>
</body>
</html>