struts2 get 请求 下载 中文处理
本文转载于:http://www.blogjava.net/xcp/archive/2009/10/29/download2.html
最近因项目需要做一个struts2下载功能,但是老是因为在做一些get请求的中文编码困扰,以下是解决方法
1. encodeURI将文本以utf-8的编码,具体参见随笔js对文字进行编码涉及3个函数:escape,encodeURI,encodeURIComponent的区别
例:
encodeURI("download.action?filenames="+filenames+"&filepaths="+filepaths);
public String getFilename() { try { return new String(filename.getBytes(), "ISO-8859-1"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return filename; } }
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" />