这里写上中文名乱码了,我可以咋解决呢?谢谢大家的指点!
http://blog.csdn.net/csh624366188/article/details/6695702
public class DownFileAction {
private String fileName;//由页面传递过来
public String execute() throws UnsupportedEncodingException{
return "success";
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) throws UnsupportedEncodingException {
this.fileName = new String(fileName.getBytes("ISO-8859-1"),"UTF-8");
}
//获取输入流
public InputStream getInputStream() throws FileNotFoundException, UnsupportedEncodingException {
String rootPath = ServletActionContext.getRequest().getSession().getServletContext().getRealPath("upload");
HttpServletResponse response = ServletActionContext.getResponse();
response.setHeader("Content-Disposition", "attachment;fileName="+java.net.URLEncoder.encode(fileName,"UTF-8"));
return ServletActionContext.getServletContext().getResourceAsStream(rootPath+"\\"+fileName);
}
}
<action name="downFile" class="com.mx.struts2.action.DownFileAction">
<result type="stream">
<param name="contentType">application/octet-stream</param>
<param name="inputName">inputStream</param>
<param name="bufferSize">2048</param>
</result>
</action>