Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

There is strange character encoding going on. I am using JSP (JSTL) and Struts with Tomat 6.

I have my JSP page encoding as such:

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

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>

the parameter on the action (java end) comes out as:

Gaz M??tro

however on the front end it is displayed as:

Gaz Métro

which is the correct way. What I can do about this??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
239 views
Welcome To Ask or Share your Answers For Others

1 Answer

Do following

1) HTML Code

 <meta contentType="text/html; charset="UTF-8"/>

2) Browser Setting for IE View -- Encoding -- Unicode (UTF-8)

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 - 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 type of response should be "application/x-www-form-urlencoded"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...