日期:2014-05-17 浏览次数:20704 次
public InputStream getInputStream() throws IOException {
if (user == null || user.getPath() == null) {
return null;
}
File file = new File(ServletActionContext.getServletContext()
.getRealPath(user.getPath()));
return new FileInputStream(file);
}
public String getContentType() {
if (user == null || user.getFilename() == null) {
return null;
}
return ServletActionContext.getServletContext().getMimeType(
user.getFilename());
}
public String getdownloadFilename() throws IOException{
if (user == null || user.getFilename() == null) {
return null;
}
return encodeDownloadFilename(user.getFilename(), ServletActionContext
.getRequest().getHeader("user-agent"));
}
public String encodeDownloadFilename(String filename, String agent)
throws IOException {
if (agent.contains("Firefox")) { // 火狐浏览器
filename = "=?UTF-8?B?"
+ new BASE64Encoder().encode(filename.getBytes("utf-8"))
+ "?=";
} else { // IE及其他浏览器
filename = URLEncoder.encode(filename, "utf-8");
}
return filename;
}
<result name="downloadOk" type="stream">
<!-- 获得2个消息表头-->
<param name="contentType">${contentType}</param>
<param name="contentDisposition">attachment;filename=${downloadFilename}</param>