2

when i submit a form in my web application some characters (f.e. german umlauts) are broken, when they enter my controller. strings like üäö endup like üäö. how do i fix this problem?

my setup looks like this:

  • spring mvc 3.1.2
  • maven 3.0.4 or 2.2.1 (tried both)
  • tomcat 7.0.x
  • eclipse (sts 3.1.0)
  • windows 8

based on answers i already found on stackoverflow i have tried following things.

added those lines to jsp's:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
...
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

spcified encoding in pom.xml:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
...

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <encoding>UTF-8</encoding>
    </configuration>
<plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <configuration>
        <encoding>UTF-8</encoding>
    </configuration>
<plugin>

changes the encoding in eclipse to UTF-8.

while investigating the problem i made following observations.

  • when i right-click files in project (resources and java files) and check the specified encoding, it says UTF-8.
  • when i output those characters in jsps(f.e. <p>öäü</p>) they are displayed correctly in the browser.
  • the problem is present in windows and linux.

thx in advance for your answers.

UPDATE:

soleved my issue by adding the CharacterEncodingFilter to my web.xml

4

2 回答 2

0

每次出现有关字符编码的问题时,我都会使用字符的 UNICODE 表示来修复它们。目前我只尝试使用韩文和德文字母。

于 2012-11-17T11:09:41.367 回答
0

查看 $TOMCAT_HOME/conf/server.xml 文件并检查编码设置:

<Connector port="8080" ... URIEncoding="UTF-8" />

似乎 Tomcat 需要此设置才能使 UTF-8 用于 HTTP 请求值,例如 GET 表单提交(也可能是 POST)中的请求参数。

于 2012-11-17T09:15:57.940 回答