简体   繁体   English

Spring和Freemarker的编码问题

[英]Encoding issues with Spring and Freemarker

I'm working on a project using Freemarker and Spring running on Jetty. 我正在使用在Jetty上运行的Freemarker和Spring进行项目。 It will involve displaying characters from many different countries so I'm trying to set the encoding to UTF-8. 它将涉及显示来自许多不同国家的字符,因此我尝试将编码设置为UTF-8。 However, no matter what I do, it remains ISO-8859-1. 但是,无论我做什么,它始终是ISO-8859-1。 I tried to create a filter in my web.xml and I've tried putting this 我试图在web.xml中创建一个过滤器,并尝试将其放入

  response.setCharacterEncoding("UTF-8");
  response.setContentType("text/html; charset=utf-8");

just before rendering the view. 就在渲染视图之前。 But when I load the page and click "View Page Info", the encoding is always ISO-8859-1. 但是,当我加载页面并单击“查看页面信息”时,编码始终为ISO-8859-1。 I've also tried hitting my app server directly to see if it was being affected by Apache but got the same result. 我还尝试过直接击我的应用服务器,以查看它是否受到Apache的影响,但得到了相同的结果。 Any help is appreciated. 任何帮助表示赞赏。

Did you try to use the spring character encoding filter in your web.xml ? 您是否尝试在web.xml中使用spring字符编码过滤器? In my case I have the following: 就我而言,我有以下几点:

 <filter>
    <filter-name>CharacterEncoding</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>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>

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

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