Tomcat的字符编码问题 [英] Character encoding issue with Tomcat
问题描述
正在进行奇怪的字符编码。我正在使用JSP(JSTL)和Struts与Tomat 6。
There is strange character encoding going on. I am using JSP (JSTL) and Struts with Tomat 6.
我的JSP页面编码是这样的:
I have my JSP page encoding as such:
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
问题是当我尝试使用encodeURI传递url时:
The issue is when I try to pass the url using encodeURI as such:
<script type="text/javascript">
$('#mailer_filter').change(function(){
var val = $(this).val();
console.log(val);
console.log(escape(val));
console.log(encodeURI(val));
location.href = 'mailList.a?' + encodeURI($(this).val());
});
</script>
动作上的参数(java end)如下:
the parameter on the action (java end) comes out as:
Gaz Métro
在前端它显示为:
Gaz Métro
这是正确的方法。我能做些什么呢?
which is the correct way. What I can do about this??
推荐答案
请关注
1)HTML代码
<meta contentType="text/html; charset="UTF-8"/>
2)浏览器设置IE
查看 - 编码 - Unicode(UTF-8)
2) Browser Setting for IE View -- Encoding -- Unicode (UTF-8)
3)Tomcat服务器
server.xml - 在连接器标签中添加URIEncoding属性为
3) Tomcat Server server.xml - In Connector tag added "URIEncoding" attribute as
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"/>
catalina.sh/catalina.bat - 追加
catalina.sh/catalina.bat - added following
set JAVA_OPTS=--Xms256m -Xmx1024m -Xss268k -server -XX:MaxPermSize=256m -XX:-UseGCOverheadLimit -Djava.awt.headless=true -Djavax.servlet.request.encoding=UTF-8 -Dfile.encoding=UTF-8
set CATALINA_OPTS=-Dfile.encoding="UTF-8"
4)响应的MIME类型应为a pplication / x-www-form-urlencoded
4) MIME type of response should be "application/x-www-form-urlencoded"
这篇关于Tomcat的字符编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!