struts1.2国际化
2013-01-22 17:52
288 查看
1、国际化资源包
application_en.properties
application_zh.properties
2、action
3、struts-config.xml配置
4、JSP
application_en.properties
#Application Resources for the "Hello" sample application #Application Resources that are specific to the hello.jsp file hello.jsp.title=Hello - A first Struts program hello.jsp.page.heading=Hello World! A first Struts application hello.jsp.prompt.person=Please enter a UserName to say hello to : hello.jsp.page.hello=Hello #Validation and error messages for HelloForm.java and HelloAction.java hello.dont.talk.to.monster=We don't want to say hello to Monster!!! hello.no.username.error=Please enter a <i>UserName</i> to say hello to!
application_zh.properties
#Application Resources for the "Hello" sample application #Application Resources that are specific to the hello.jsp file hello.jsp.title=\u4f60\u597d\uff0c\u7b2c\u4e00\u4e2astruts\u9879\u76ee hello.jsp.page.heading=\u793e\u4f1a\u4f60\u597d\uff0c\u6211\u7684\u7b2c\u4e00\u4e2astruts\u9879\u76ee hello.jsp.prompt.person=\u8bf7\u5199\u4e0b\u4f60\u7684\u540d\u5b57\uff0c\u6211\u4eec\u53ef\u4ee5\u4e0e\u4ed6\u6253\u62db\u547c hello.jsp.page.hello=\u4f60\u597d #Validation and error messages for HelloForm.java and HelloAction.java hello.dont.talk.to.monster=\u6211\u4eec\u4e0d\u80fd\u5bf9Monster\u8bf4\u4f60\u597d hello.no.username.error=\u8bf7\u8f93\u5165\u59d3\u540d
2、action
package hello; import java.util.Locale; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.Globals; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; public class LocalAction extends Action { @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // TODO Auto-generated method stub String language=request.getParameter("language"); //获取当前语言国际化 //Locale locale=request.getLocale(); //new locale对象 Locale newlocale=new Locale(language,""); //覆盖session中国际化对象 request.getSession(true).setAttribute(Globals.LOCALE_KEY, newlocale); return mapping.findForward("success"); } }
3、struts-config.xml配置
<action path="/localAction" type="hello.LocalAction" scope="request" > <forward name="success" path="/hello.jsp"></forward> </action>
4、JSP
<h3>Language Options</h3> <ul> <li><html:link action="localAction?language=en">English</html:link></li> <li><html:link action="localAction?language=zh">China</html:link></li> </ul>
相关文章推荐
- Struts 1.2国际化初解
- Struts1.2国际化实例
- struts、spring国际化资源文件使用简介
- Struts1.2文件下载(解决中文乱码)
- Struts1.2
- struts1.2原理
- 一口一口吃掉Struts(九)——国际化问题(1) .
- Struts第八篇【资源国际化、对比JSP的资源国际化】
- struts1.2一些知识
- struts1.2上传多个文件
- Struts+Mysql+Tomcat5.0.28+mysql-connector-java-3.0.16-ga-bin.jar 国际化乱码解决方法
- 关于struts国际化的一点尝试
- struts——国际化的实现
- 在struts中使用国际化(i18n)
- Struts国际化规则
- Struts中html:button、html:submit、html:cancel等标签中的文字如何国际化?
- struts-2 国际化的个人理解
- struts国际化处理
- struts国际化问题解决方案
- struts国际化