Tiles2 Struts切换区域设置 [英] Tiles2 Struts Switch Locale

查看:79
本文介绍了Tiles2 Struts切换区域设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是struts2和tile2的新手,我有一个应用程序,其中我使用struts2作为mvc框架,并使用tile2作为视图组件. 在我的应用程序中,我使用2种语言英语和马拉地语,各自的语言环境为en_US和mr_IN 我有Tiles.xml和Tiles_mr_IN.xml 当我从浏览器切换语言环境时,代码工作正常 但是我想在英语和马拉地语之间切换,并且应该使用相同的请求参数将用户重定向到相同的操作. 我已经尝试过satting request_locale参数,但是没有用. 我可以发现,如果我可以在请求标头中切换语言环境或将语言环境从struts2传递给tile lisner或类似的东西 请帮助

I am newbee to struts2 and tiles2, I am having an application where i m using struts2 as mvc framework and tiles2 as a view component. In my application I am using 2 languages English and Marathi the respective locales are en_US and mr_IN I have tiles.xml and tiles_mr_IN.xml when i switch locale from browser the code works fine but i want to toggle between English and Marathi and the user should be redirected to same action with same request parameters. I have tried satting request_locale parameter but it didnt work. I could find that if i could switch locale in the request header or pass locale from struts2 to tiles lisner or some thing like that please help

推荐答案

使用两个s2 jsp标记即可解决此问题.

This issue should be resolvable with a couple s2 jsp tags.

此链接显示了您需要的部分内容: http://struts.apache.org/2.0.14/docs/how-do-we-change-locales.html

This link shows part of what you need: http://struts.apache.org/2.0.14/docs/how-do-we-change-locales.html

这就是显示如何使用s2 url添加参数,然后使用该参数来设置语言环境.

That is it shows how to take a s2 url add a parameter and then use that to set the locale.

如果i18n拦截器中有一个名为"request_locale"的参数,它将在用户代理语言首选项上使用该参数.

If there is a parameter called "request_locale" coming in the i18n interceptor will use that over the user agents language preference.

使示例更适合于模板更改

To make the example better suited for a template change

<s:url id="en" action="Welcome">

<s:url includeParams="get">

请注意,操作名称已被省略,这将默认为当前操作(最适合您的模板),接下来includeParams ="get"将所有参数重新添加到url中,以便将它们传递给使用锚点时的操作. includeParams可以是"none","get"或"all"(按照您的期望进行).有关s2网址标签的更多信息,请参见: http://struts.apache.org /2.2.1.1/docs/url.html

Notice the action name has been omitted, this will default to the current action (which is ideal for your template) next the includeParams="get" will add all the parameters back into the url so they'll be passed into the action when you use the anchor. The includeParams may be "none", "get" or "all" (doing what you would expect). For more information on the s2 url tag see: http://struts.apache.org/2.2.1.1/docs/url.html

进一步请注意,s2 a标签与s2 url标签具有大多数相同的功能,利用此功能将产生:

Further note that the s2 a tag shares most of the same funcationality as the s2 url tag taking advantage of this will produce:

<s:a includeParams="get">
  <s:param name="request_locale" value="en_US"/>
  English
</s:a>
&nbsp;
<s:a includeParams="get">
  <s:param name="request_locale" value="mr_IN"/>
  Marathi
</s:a>

这篇关于Tiles2 Struts切换区域设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆