struts2实现国际化
来源:互联网 发布:联通软件下载 编辑:程序博客网 时间:2024/06/03 12:30
这里国际化指页面的中英文转换。
首先来看一个页面:
这里我们要实现的是点击上方按钮实现页面的中英文转换,英文界面如下:
当然我们可以根据点击的链接跳转到不同的页面,但是这样每个页面需要写2次(中文一次,英文一次)。很麻烦。
下面我们使用添加属性文件的方法来实现这个功能。
1.建立属性文件:
Global_zh_CN.properties:
language=\u8BED\u8A00chinese=\u4E2D\u6587english=\u82F1\u6587loginpage=\u767B\u5F55\u9875\u9762username=\u7528\u6237\u540Dpassword=\u5BC6\u7801enter=\u786E\u5B9A
Global_en_US.properties:
language=Languagechinese=Chineseenglish=Englishloginpage=LoginPageusername=Usernamepassword=Passwordenter=Enter
2.写页面
这里使用了struts2中标签来写:
<%@ page contentType="text/html;charset=utf-8" %><%@ taglib prefix="s" uri="/struts-tags" %><center><s:text name="language"></s:text>:<a href=Change?key=1><s:text name="chinese"></s:text></a> | <a href=Change?key=2><s:text name="english"></s:text></a><br/><h3><s:text name="loginpage"></s:text></h3><s:form action="Login" method="post"><s:textfield name="u.username" key="username" /><s:password name="u.password" key="password" /><s:submit key="enter" /></s:form></center>
我们可以看到,这里我们的name都是属性文件中的name属性。
3.在struts.xml文件中添加属性文件的配置:
4.在com.action包下写一个转换action用来转换
action如下:
package com.action;import java.util.Locale;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;public class ChangeAction extends ActionSupport{ private String key; private Locale l; public String getKey() { return key; } public void setKey(String key) { this.key = key; } public String execute() { if(key.equals("1")) l=Locale.CHINA; else l=Locale.US; ActionContext.getContext().setLocale(l); return SUCCESS; }}
最后,在struts.xml将该action配置一下即可。
0 0
- struts2实现国际化
- struts2实现国际化
- struts2实现国际化
- struts2国际化实现过程
- Struts2 的国际化实现
- Struts2 的国际化实现
- Struts2 的国际化实现
- Struts2 的国际化实现
- Struts2 的国际化实现
- Struts2实现国际化
- Struts2的国际化实现
- Struts2 的国际化实现
- struts2实现国际化
- Struts2 本地化/国际化实现
- struts2实现国际化
- Struts2 的国际化实现
- struts2 用户自定义实现国际化
- 国际化之struts2实现研究
- 导航菜单栏
- 实验探究 ioremap
- 在AndroidStudio中集成Genymotion模拟器
- python 画图--简单开始及折线图
- Android样式的开发:shape篇
- struts2实现国际化
- 高手速成android开源项目【View篇】
- BZOJ1019: [SHOI2008]汉诺塔
- 昂贵的聘礼--floyd
- iOS学习笔记
- 对Button上image 和 title 位置进行设置
- MVC,MVP 和 MVVM 的图示
- Cocos2dx C++与Lua合并开发的VS配置环境搭建
- DecimalFormat类的使用