简体   繁体   中英

Tomcat 7 with UTF-8 encode

Case 1: I have a virtual machine with Ubuntu and Tomcat 7.x. If i POST data with special characters to the server i'ts ok. I have a filter that run before any servlet and set the encode to UTF-8 request.setCharacterEncoding("utf-8");

Case 2: In the same virtual machine i have other Tomcat 7.x installation (reply). Now i installed the JOSSO 1.8.6 on Tomcat 7.x. After this when i try to submit POST data with special characters the servlet don't decode correctly request.getParameter("reportText"); .

I believe that the JOSSO have any filter that run before my Encode Filter and uses the request what makes my filter request.setCharacterEncoding("utf-8") useless.

What i try to resolve the problem:

  • I have set the URIEncoding="utf-8" at the Tomcat Connector tag (server.xml).
  • I have used setCharacterEncoding().
  • I have set the JAVA_OPTS="$JAVA_OPTS -Djavax.servlet.request.encoding=UTF-8 -Dfile.encoding=UTF-8" on tomcat setenv.sh
  • I checked the HTTP Headers and they are correct (Content-Type=text/plain;charset=utf-8)
  • I have enable Tomcat filter setCharacterEncodingFilter

The POST request is generated by client JSP

<form id="xx" name="xx" onsubmit="return validateAndSubmitForm(this);" action="submitReport.do" method="post" enctype="application/x-www-form-urlencoded; charset: utf-8;"> xxx </form>

My JSP tag on top:

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

POST headers: image with the headers

Any ideas? Thank you.

I added the URIEncoding attribute of the Connector element of the server.xml file which is the configuration file of tomcat.

My code is the following.

<Connector URIEncoding="UTF-8" connectionTimeout="20000" port="8082" protocol="HTTP/1.1" redirectPort="8443"/>    
<Connector URIEncoding="UTF-8" port="8009" protocol="AJP/1.3" redirectPort="8443"/>

The solution that work for me is add URIEncoding to server.xml file into of ubuntu configuration.

<Connector URIEncoding="UTF-8" connectionTimeout="20000" port="8082" protocol="HTTP/1.1" redirectPort="8443"/>    
<Connector URIEncoding="UTF-8" port="8009" protocol="AJP/1.3" redirectPort="8443"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM