`
7wolfs
  • 浏览: 178502 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

struts 开发笔记

    博客分类:
  • Java
IO 
阅读更多
1,struts默认根据http request请求流中的键值(Accept-Language en-US,zh-CN;q=0.5)设定locale值。
参见 xwork2 中ActionContext 的处理。com.opensymphony.xwork2.ActionContext.getContext(),150th line。

struts中多语言处理中,取不同语言的文本内容时,语言版本获取是从ActionContext.getContext().getLocale()中取得。ActionContext中locale设置在com.opensymphony.xwork2.interceptor.I18nInterceptor拦截器中进行,该拦截器默认是激活状态。


2, struts2,spring 国际化:

首先通过xwork2 I18nInterceptor设置locale。在http request的parameter中加入request_locale参数。或者在request.getSession()中加入属性为I18nInterceptor.DEFAULT_SESSION_ATTRIBUT的Locale对象。

1. spring中messageSource在java中对多语言的处理:
在使用ActionContext.getContext().getLocale()前设置好ActionContext中的Locale。
在vseaf acegi的验证中,会清空session,所以VSAuthenticationProcessingFilter.attemptAuthentication中加入session对locale的保存处理。
// 为xwork2 ActionContext设置语言区域,actionContext会在I18nInterceptor拦截请求时重新设置语言区域
// spring messageResource 的ResourceBundleMessageSource getMessage方法将从xwork2 ActionContext中取得语言区域
request.getSession().setAttribute(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE, locale); //它影响到I18nInterceptor里的语言区域设置

2. jsp,spring:message tag:
spring:message tag获取多语言文本信息前,RequestContext initContext会设置locale,之后,tag使用RequestContext提供的locale。
在请求转给jsp之前,在VSEAFAction中,给httpRequest和httpSession设置RequestContext所需要的locale参数。
HttpRequest发生跳转后,原有的属性都会消失,而HttpSession内容会保留。struts接受到URL包含.actin的请求后,根据struts配置文件找到对应的action类,并执行该类,然后跳转到指定的页面上。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics