【问题标题】:Regional Characters not getting Displayed on JSP pageJSP 页面上不显示区域字符
【发布时间】:2015-12-20 07:38:54
【问题描述】:

我已使用 Spring 的 Maven Webapp 进行格式化,以具有英语和孟加拉语的本地化功能。我分别从英语和孟加拉语的属性文件加载页面所需的消息。如果我直接将字符添加到页面,它们会正确呈现。此外,如果我在 unicode(例如:স)中添加孟加拉语字符,它们会正确显示。但由于属性文件不容易读取,我在普通孟加拉语文本中添加了文本(例如:স),但现在它们无法正确显示。它们显示为“à¦à¦¦à§à¦”等。

在每个 JSP 页面中,我都有以下内容。

<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>

在我的 web.xml 中,我已经包含了

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

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

我也有,

<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <page-encoding>UTF-8</page-encoding>
    </jsp-property-group>
</jsp-config>

在我的 spring-servlet.xml 中

<bean id="messageSourceLocale"
      class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename" value="messages.messages" />
    <property name="defaultEncoding" value="UTF-8" />
</bean>

我做错了什么?如何解决这个问题?提前致谢。

【问题讨论】:

    标签: java spring jsp maven utf8-decode


    【解决方案1】:

    我在使用稍微不同的技术(Stspring、Maven、Pug(前 Jade))时遇到了同样的问题。 在我的控制器中添加这一行对我有用:

    @RequestMapping(value="/", produces = "text/html;charset=UTF-8")
    

    感谢this post

    希望对您有所帮助!

    【讨论】:

      猜你喜欢
      • 2012-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-26
      • 2015-07-10
      • 1970-01-01
      • 2019-09-29
      相关资源
      最近更新 更多