[英]Ubuntu/Tomcat Server UTF-8 encoding issue
I have developing a web application using Java/Jsp running on an Ubuntu 14.04 LTS server with Tomcat 8, where the following UTF-8 encoding problem with the section sign § apperas. 我已经开发了一个使用Java / Jsp的Web应用程序,该Web应用程序在具有Tomcat 8的Ubuntu 14.04 LTS服务器上运行,其中以下UTF-8编码问题带有部分符号§apperas。
Any form Input of the section sign § at the server side will is converted to § and I have no clue why. 服务器端的部分符号§的任何形式的输入都将转换为§ ,我不知道为什么。
Simple sysout: 简单的sysout:
Should Print [§] - [output]: § Char: § ASCII 167
The HTML/Client side is ok since a wireshark trace shows me the correct char § is delivered to the server. HTML / Client端正常,因为wireshark跟踪向我显示了正确的char§已传递到服务器。 So the issues must be at the tomcat-server itself.
因此,问题必须出在tomcat服务器本身。
The following things are set already: 已经设置了以下内容:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <meta charset="utf-8" />
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Set CharSet to UTF-8 response.setContentType("text/html; charset=UTF-8"); response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8");
locale -a C C.UTF-8 en_US.utf8 POSIX
env JAVA_OPTS="-Djava.awt.headless=true - Djava.security.egd=file:/dev/./urandom - Djavax.servlet.request.encoding=UTF-8 -Dfile.encoding=UTF-8" env CATALINA_OPTS="-Xms512M -Xmx1024M -server -XX:+UseParallelGC - Dfile.encoding=UTF-8"
server.xml - In Connector tag for the GET (not really relevant for me) added "URIEncoding" attribute as server.xml-在GET的连接器标签中(与我无关),将“ URIEncoding”属性添加为
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"/>
and uncommented the UTF-8 filter within the web.xml 并取消注释web.xml中的UTF-8过滤器
<filter>
<filter-name>setCharacterEncodingFilter</filter-name>
<filter-
class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
encoding</param-name>
UTF-8</param-value>
</init-param>
<async-supported>true</async-supported>
</filter>
Now I'm out of ideas and hope for some helpful hints :) 现在我没主意了,希望有一些有用的提示:)
thanks! 谢谢!
Edit: It seems that any UTF-8 Code > U+00A0 are not working correctly snippet 编辑:似乎任何UTF-8代码> U + 00A0均无法正常工作
U+00A1 ¡ c2 a1 INVERTED EXCLAMATION MARK U+00A2 ¢ c2 a2 CENT SIGN U+00A3 £ c2 a3 POUND SIGN U+00A4 ¤ c2 a4 CURRENCY SIGN ... Sysout: ¡ ¢ ã ä...
EDIT: 编辑:
I've tried anything I've found but its still not working: System.properties() returns the following. 我已经尝试了所有找到的东西,但是仍然无法正常工作:System.properties()返回以下内容。 Perhaps someone has another idea.
也许有人有另一个主意。
logger.debug("SETTINGS: " + System.getProperties() );
...
file.encoding.pkg=sun.io
javax.servlet.request.encoding=UTF-8
sun.jnu.encoding=ANSI_X3.4-1968
file.encoding=UTF-8
sun.io.unicode.encoding=UnicodeLittle
....
At the top of the jsp: 在jsp的顶部:
<%@page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"
%><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
(I am afraid such is already the case.) Inspect in the browser the page encoding and the HTML source text. (恐怕已经是这种情况了。)在浏览器中检查页面编码和HTML源文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.