I18N charset Encoding Spring-JSP

北战南征 提交于 2019-12-25 16:02:12

问题


I'm trying to show é as a title of my form:input field, and I can't get it working.

Example 1 :

<form:input type="text" path="something" title="é"/>

Output :

Example 2 :

<input type="text" title="<spring:message code="mySpecialChar" />"/>

Output :

Example 3 :

<form:input type="text" path="something" title="<spring:message code="mySpecialChar" />"/>

Output :

Error, I'm not allowed to do that, to solve this, I've tried Example 4.

Example 4 :

<spring:message code=mySpecialChar" var="mySpecialChar"/>
<form:input type="text" path="something" title="${mySpecialChar}"/>

Output :

How can I get my Example 4 working properly ?


回答1:


After a quick search, I've found that I have to add htmlEscape="false" to my <spring:message> tag.

Spring:message docs




回答2:


You would need to unescape your value in a Controller, first thing you would have to autowire your MessageSource

@Autowired
private MessageSource messageSource;

than you can unescape using e.g. StringEscapeUtils

 String message = messageSource.getMessage("mySpecialChar", null, Locale.getDefault());
 model.addAttribute("mySpecialChar", StringEscapeUtils.unescapeHtml([YOUR VALUE]));

than just

<form:input type="text" path="something" title="${mySpecialChar}"/>


来源:https://stackoverflow.com/questions/27797756/i18n-charset-encoding-spring-jsp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!