Jsp JSTL i18n fmt属性设置

Jsp JSTL i18n fmt属性设置,jsp,internationalization,jstl,resourcebundle,Jsp,Internationalization,Jstl,Resourcebundle,试图使用JSTL创建i18n应用程序,我有以下几点: <li><a href="admin/insertEmployee.jsp"><fmt:message key="new"/></a></li> 已解决: 我在web.xml中定义了默认语言环境pt_pt <context-param> <param-name> javax.servlet.jsp.jstl.fmt.locale

试图使用JSTL创建i18n应用程序,我有以下几点:

<li><a href="admin/insertEmployee.jsp"><fmt:message key="new"/></a></li>
已解决: 我在web.xml中定义了默认语言环境pt_pt

<context-param>
    <param-name>
        javax.servlet.jsp.jstl.fmt.locale
    </param-name>
    <param-value>
        pt_PT
    </param-value>
</context-param>

javax.servlet.jsp.jstl.fmt.locale
pt_pt
在index.jsp中,如果url作为参数提供,则使用代码声明资源包和覆盖区域设置(示例->/?lang=en_US)


使用scope=“session”,适用于所有JP。 更改语言(英语)的演示链接


我在com.arthurportas.i18n包下有两个文件: Messages\u pt\u pt.properties和Messages\u en\u US。 在jsp文件内部,使用以下内容翻译文本,例如:

<fmt:message key="employee"/>

唯一奇怪的行为是,通过点击链接选择英文翻译,需要双击!!一次单击被忽略…这是浏览器缓存行为吗

@亚瑟·波塔斯:唯一奇怪的行为是,通过点击链接选择英文翻译,需要双击!!一次单击被忽略…这是浏览器缓存行为吗

这是因为您在setBundle之后设置了区域设置。正确的顺序是:

<c:if test="${param['lang'] !=null}">
    <fmt:setLocale value="${param['lang']}" scope="session" />
</c:if>
<fmt:setBundle basename="com.arthurportas.i18n.Messages"/>

<fmt:message key="employee"/>
<c:if test="${param['lang'] !=null}">
    <fmt:setLocale value="${param['lang']}" scope="session" />
</c:if>
<fmt:setBundle basename="com.arthurportas.i18n.Messages"/>