【发布时间】:2011-03-05 03:01:32
【问题描述】:
我的网站编码遇到了一个大问题! 我使用 spring 3、tomcat 6 和 mysql db。我想在我的网站中支持德语和捷克语以及英语,我将所有 JSP 创建为 UTF-8 文件,并且在每个 jsp 中我包含以下内容:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
我创建了 messages.properties(默认为捷克语)、messages_de.properties 和 messages_en.properties。并且全部保存为 UTF-8 文件。
我在 web.xml 中添加了以下内容:
<filter>
<filter-name>encodingFilter</filter-name>
<filterclass>
org.springframework.web.filter.CharacterEncodingFilter</filterclass>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<locale-encoding-mapping-list>
<locale-encoding-mapping>
<locale>en</locale>
<encoding>UTF-8</encoding>
</locale-encoding-mapping>
<locale-encoding-mapping>
<locale>cz</locale>
<encoding>UTF-8</encoding>
</locale-encoding-mapping>
<locale-encoding-mapping>
<locale>de</locale>
<encoding>UTF-8</encoding>
</locale-encoding-mapping>
</locale-encoding-mapping-list>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
并将以下内容添加到我的 applicationContext.xml:
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource"
p:basenames="messages"/>
<!-- Declare the Interceptor -->
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"
p:paramName="locale" />
</mvc:interceptors>
<!-- Declare the Resolver -->
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />
我在server.xml的元素中将useBodyEncodingForURI属性设置为true:%CATALINA_HOME%/conf,另外一次尝试添加URIEncoding="UTF-8"。
我使用字符集 [utf8] 和集合 [utf8_general_ci] 创建了所有表和字段
我浏览器的编码是 UTF-8(顺便说一句,我有 IE8 和 Firefox 3.6.3)
当我打开 MYSQL 查询浏览器并手动插入捷克语或德语数据时,它被正确插入,并且在我的应用程序中也正确显示。
所以,这是我遇到的问题列表:
默认情况下应该加载messages.properties(捷克语),而不是默认加载messages_en.properties。
在 web 表单中,当我输入捷克语数据时,然后单击提交,在控制器中我打印出控制台中的数据,然后将其保存到数据库,打印的内容不正确,有奇怪的字符,并且这是保存到 db 的确切数据。
不知道哪里错了!为什么我不能让它发挥作用,尽管我做了人们所做的事情并为他们工作!不知道。。
请帮帮我,我被这个糟糕的问题困扰了好几天了,这让我发疯了!
提前谢谢你。
【问题讨论】:
标签: spring tomcat character-encoding