value = "DownloadOperationDoc",
results = {
@Result(name = "success", type = "stream",
params = {"contentType",
"application/octet-stream;charset=UTF-8", "inputName",
"InputStream",
"contentDisposition",
"attachment;filename=\"${headerFileName}\"",
"bufferSize", "4096"}),
@Result(name = "login", location = "/pages/welcome.jsp"),
}
)
public String DownloadOperationDoc() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
@SuppressWarnings("unused")
HttpServletResponse response = ServletActionContext.getResponse();
// response.addHeader( "Content-Disposition", "attachment;filename=\"${fileName}\"",);
HttpSession session = request.getSession();
setLoggedIn((String) session.getAttribute("loggedIn"));
if (getLoggedIn() == null) {
setMessage("请登录!");
return LOGIN;
}
return SUCCESS;
}
//
public InputStream getInputStream() throws Exception {String fileName = ServletActionContext.getRequest().getParameter("fileName");
IFile iFile = OuterFileUtil.getFile(fileName);
return OuterFileUtil.getInputStream(iFile);
}
//下载的文件名
@SuppressWarnings("unused")
private String headerFileName;
public String getHeaderFileName() {
try {
// return java.net.URLEncoder.encode( fileName, "UTF-8");
// fileName = new String((main.getWwmWorkflowName()+"_"+time+".xml"));
// getHttpResponse().setCharacterEncoding("UTF-8");
// fileName=java.net.URLEncoder.encode(fileName,"UTF-8");
// getHttpResponse().setHeader("Content-Disposition", "attachment; filename=" +new String(fileName.getBytes("UTF-8"),"GBK"));
HttpServletRequest request = ServletActionContext.getRequest();
String fileState = request.getParameter("fileState");
System.out.println("#################"+fileState);
String encodedFileName = "";
if("1".equals(fileState)){
int index = fileName.lastIndexOf(".");
String reName = fileName.substring(0,(index-36))+fileName.substring(index);
encodedFileName = java.net.URLEncoder.encode( reName, "UTF-8");
}else{
encodedFileName = java.net.URLEncoder.encode( fileName, "UTF-8");
}
return new String(encodedFileName.getBytes("UTF-8"),"GBK");
// return new String(encodedFileName.getBytes("UTF-8"), "ISO8859-1");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return null;
}
}