[英]Struts2 localize interceptor
I'm trying to create an Interceptor able to change the language but I can not change it. 我正在尝试创建一个能够更改语言的拦截器,但是我无法更改它。
Relevant Interceptor code: 相关拦截器代码:
public String intercept(ActionInvocation invocation) throws Exception {
ActionMapping mapping = (ActionMapping) invocation
.getInvocationContext()
.get(ServletActionContext.ACTION_MAPPING);
Map<String, Object> params = mapping.getParams();
if (params != null) {
Locale locale = (Locale) params.remove(LOCALE_PARAMETER);
if (locale != null) {
ActionContext.getContext().setLocale(locale);
}
}
return invocation.invoke();
}
struts.xml: struts.xml:
<package name="default" extends="struts-default" namespace="/">
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<interceptors>
<interceptor name="navigator"
class="it.apps.mca.web.interceptors.NavigatorInterceptor">
</interceptor>
<interceptor name="locale"
class="it.apps.mca.web.interceptors.internationalizations.LocaleInterceptor">
</interceptor>
<interceptor-stack name="customStack">
<interceptor-ref name="navigator" />
<interceptor-ref name="locale" />
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<action name="locale"
class="it.apps.mca.web.actions.internationalizations.LocaleAction">
<interceptor-ref name="customStack"></interceptor-ref>
<result name="success" type="redirect">
<param name="location">${target}</param>
<param name="parse">true</param>
</result>
</action>
<action name="login"
class="it.apps.mca.web.actions.authentication.LoginAction">
<result name="success" type="tiles">/welcome.tiles</result>
<result name="input">index.jsp</result>
<result name="error">index.jsp</result>
</action>
</package>
I know i18n interceptor already exists. 我知道i18n拦截器已经存在。 I added an interceptor that performs redirections. 我添加了执行重定向的拦截器。 After adding this interceptor, I lose the location of the page. 添加此拦截器后,我丢失了页面的位置。 The same thing happens if I perform a redirect through the action. 如果我通过操作执行重定向,则会发生相同的情况。 You know tell me the reason? 你知道告诉我原因吗?
That Interceptor already exists: i18n Interceptor
该拦截器已经存在: i18n Interceptor
It is part of the defaultStack, so you don't have to manually include it. 它是defaultStack的一部分,因此您不必手动包含它。
Other info in this answer . 此答案中的其他信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.