action 從前台頁面接受到文件名,傳到action裡的時候中文亂碼?
下載下來的文件名字亂碼.打開後內容頁亂碼?
前台從數據查出來的:下載/s:a
後台:
private String fileName;
private Datum d;(getter,setter給了)
public InputStream getInputStream() throws Exception{
this.fileName=d.getDatumname();
System.out.println(d.getDatumname());
System.out.println(fileName);
ServletActionContext.getResponse().setHeader("Content-Disposition","attachment;fileName="+java.net.URLEncoder.encode(fileName, "utf-8"));
return ServletActionContext.getServletContext().getResourceAsStream("upload"+"//"+fileName);
}
public String execute(){
return SUCCESS;
}
}
struts.xml:
<result name="success" type="stream">
<param name="contentType">application/octet-stream;charset=iso8599-1</param>
<param name="inputName">inputStream</param>
<param name="bufferSize">4096</param>
<param name="contentDisposition">attachment;filename="${fileName}"</param>
</result>
</action>
這是哪兒出錯了啊?
ssh,myeclips,tomcat7
1 最好 把tomcat conf下面 的 servlet.xml 文件裡面 端口標簽裡面 加上URIEnCoding="UTF-8"
2 ServletActionContext.getRequest().setCharacterEncoding("UTF-8");//設置請求報文
ServletActionContext.getResponse().setCharacterEncoding("UTF-8");//設置響應報文
3 jsp參數值用encodeURIComponent這個;
var a = "中國";
a = encodeURIComponent(encodeURIComponent(a));