Struts i18n 显示 unicode 而不是特殊字符
Struts i18n showing unicode instead of special char
我目前正在进行 struts 迁移。我从 struts 2.2.3.1 升级到 2.5.10.1,瓷砖从 2.2.2 升级到 3.0.8
对于表单标签翻译,我使用了一些 ISO-8859-1 编码的属性文件。这曾经有效,文件中的欧元符号如“\u20AC”过去在导航器上正确显示。
但是在图书馆升级后,代码\u20AC直接显示在导航器上,而不是€。
要在 JSP 中显示 i18n 标签,我使用以下代码:
<s:text name="%{getText('lbl.to.pay', null, price)}"/>
在 message_en.properties 我得到了:
lbl.to.pay=Your fees are {0}\u20AC
应该显示:
"Your fees are 100€"
但我有:
"Your fees are 100\u20AC"
在每个 jsp 我有:
<%@ page language="java" contentType="text/javascript; charset=UTF-8"
pageEncoding="UTF-8"%>
...
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
在 web.xml 我得到了:
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<page-encoding>UTF-8</page-encoding>
</jsp-property-group>
</jsp-config>
...
<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>
在struts.xml中:
<constant name="struts.i18n.encoding" value="UTF-8" />
此配置用于旧库,库升级后我没有对此进行任何更改。
如果我直接在 jsp 中添加一个 €,它会正确显示。
知道要做什么吗?
编辑 :
这在我使用时工作得很好:
<s:text name="lbl.ccip.checkout.to.pay" />
但仍然有同样的问题:
<s:text name="%{getText('lbl.ccip.checkout.to.pay')}" />
因此,问题似乎出在 getText() 方法上,我必须在上面的示例中使用该方法,因为我使用了占位符 {0}
实际上,如果我使用而不是调用 getText(),它就可以正常工作:
<s:text name="lbl.to.pay" >
<s:param value="%{price}"/>
</s:text>
我目前正在进行 struts 迁移。我从 struts 2.2.3.1 升级到 2.5.10.1,瓷砖从 2.2.2 升级到 3.0.8
对于表单标签翻译,我使用了一些 ISO-8859-1 编码的属性文件。这曾经有效,文件中的欧元符号如“\u20AC”过去在导航器上正确显示。
但是在图书馆升级后,代码\u20AC直接显示在导航器上,而不是€。
要在 JSP 中显示 i18n 标签,我使用以下代码:
<s:text name="%{getText('lbl.to.pay', null, price)}"/>
在 message_en.properties 我得到了:
lbl.to.pay=Your fees are {0}\u20AC
应该显示:
"Your fees are 100€"
但我有:
"Your fees are 100\u20AC"
在每个 jsp 我有:
<%@ page language="java" contentType="text/javascript; charset=UTF-8"
pageEncoding="UTF-8"%>
...
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
在 web.xml 我得到了:
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<page-encoding>UTF-8</page-encoding>
</jsp-property-group>
</jsp-config>
...
<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>
在struts.xml中:
<constant name="struts.i18n.encoding" value="UTF-8" />
此配置用于旧库,库升级后我没有对此进行任何更改。
如果我直接在 jsp 中添加一个 €,它会正确显示。
知道要做什么吗?
编辑 :
这在我使用时工作得很好:
<s:text name="lbl.ccip.checkout.to.pay" />
但仍然有同样的问题:
<s:text name="%{getText('lbl.ccip.checkout.to.pay')}" />
因此,问题似乎出在 getText() 方法上,我必须在上面的示例中使用该方法,因为我使用了占位符 {0}
实际上,如果我使用而不是调用 getText(),它就可以正常工作:
<s:text name="lbl.to.pay" >
<s:param value="%{price}"/>
</s:text>