简体   繁体   English

Spring MVC和Thymeleaf波兰语签署编码

[英]Spring MVC and Thymeleaf Polish signs encoding

First of all, i know there are bunch of topic such mine, but I was looking for solution in stackoverflow and i couldn't come up with solution. 首先,我知道有很多这样的话题,但是我一直在寻找stackoverflow中的解决方案,但我无法提出解决方案。 My problem is charset encoding in Spring MVC. 我的问题是Spring MVC中的字符集编码。 In my case I'm talking about polish letters like ę,ó,ż etc. 就我而言,我说的是波兰字母(如ę,ó,ż等)。

I've tried everything, starting from CharacterEncodingFilter, setting UTF-8 encoding in maven pom.xml, setting UTF-8 encoding and Content-type also UTF-8 in ThymeleafViewResolver and TemplateResolver. 我已经尝试了所有方法,从CharacterEncodingFilter开始,在maven pom.xml中设置UTF-8编码,在ThymeleafViewResolver和TemplateResolver中设置UTF-8编码和Content-type以及UTF-8。

I can't manage to make it working with polish signs. 我无法使其与波兰标志一起使用。 What is important, my html pages include polish signs, but when i sent form data in post method of course, it translate utf-8 signs to ISO-8859-1. 重要的是,我的html页面包含波兰语符号,但是当我用post方法发送表单数据时,它会将utf-8符号转换为ISO-8859-1。

So when i send data like this one: Żyrardów 因此,当我发送这样的数据时: Żyrardów

I data from request in Controller like this one: Å»yrardów 我像这样从控制器中的请求获取数据: Å»yrardów

Is there any solution apart from converting signs on every request in my controller? 除了在控制器中的每个请求上转换符号外,是否还有其他解决方案?

new String(ppForm.getCity().getBytes("ISO-8859-1"), "utf-8")

Thanks in advance, i hope someone can provide solution. 在此先感谢,希望有人能提供解决方案。

@UP I've also set URIEncoding in tomcat server.xml file, but it didn't work. @UP我也已经在tomcat server.xml文件中设置了URIEncoding,但是没有用。

  <Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" 
            URIEncoding="UTF-8" />

   <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8" />

try like this : 尝试这样:

(web.xml) (web.xml)

<!-- encoding filter -->
<filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>
        org.springframework.web.filter.CharacterEncodingFilter
</filter-class>

<init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

(thymeleaf settings) (百叶窗设置)

<!-- thymeleaf settings -->
<beans:bean id="templateResolver"
    class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
    <beans:property name="prefix" value="/WEB-INF/views/" />
    <beans:property name="suffix" value=".html" />
    <beans:property name="templateMode" value="HTML5" />
    <beans:property name="cacheable" value="false"></beans:property>
    <beans:property name="characterEncoding" value="UTF-8"></beans:property>
    <beans:property name="order">
        <beans:value>1</beans:value>
    </beans:property>
</beans:bean>

<beans:bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
    <beans:property name="templateResolver" ref="templateResolver" />
    <beans:property name="additionalDialects">
        <beans:set>
            <beans:bean
                class="org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect"></beans:bean>
        </beans:set>
    </beans:property>
</beans:bean>

<beans:bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
    <beans:property name="templateEngine" ref="templateEngine" />
    <beans:property name="characterEncoding" value="UTF-8"></beans:property>
</beans:bean>

don`t works. 不起作用。 you add your code and comment me. 您添加代码并评论我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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