設置Tomcat編碼格式爲UTF-8:修改tomcat-->conf-->server.xml文件,設置URIEncoding爲UTF-8,不設置時默認值爲ISO8859-1java
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"/>
apache
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8"/>tomcat
項目及Java文件,JSP文件格式固然也要是UTF-8this
java代碼編碼
/**
* 設置下載文件名
* @param downloadFileName
*/
public void setDownloadFileName(String downloadFileName) {
try {
HttpServletRequest request=ServletActionContext.getRequest();
if (request.getHeader("User-Agent").toLowerCase()
.indexOf("firefox") > 0) {
this.downloadFileName = "=?UTF-8?B?"
+ (new String(org.apache.commons.codec.binary.Base64.encodeBase64(downloadFileName
.getBytes("UTF-8")))) + "?=";
} else {
this.downloadFileName = java.net.URLEncoder.encode(
downloadFileName, "UTF-8");
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
.net