Tomcat 的字符编码问题 [英] Character encoding issue with Tomcat

查看:28
本文介绍了Tomcat 的字符编码问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在进行奇怪的字符编码.我在 Tomat 6 中使用 JSP (JSTL) 和 Struts.

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端)上的参数输出为:

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 类型的响应应该是application/x-www-form-urlencoded"

4) MIME type of response should be "application/x-www-form-urlencoded"

这篇关于Tomcat 的字符编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆