Struts2_08_Struts2国际化实例
2018-03-03 10:59
288 查看
1、建立properties文件
在src目录下建立如下形式的三个文件baseName_language_country.properties
baseName_language.properties
baseName.properties
globe_en_US.properties
globe_zh_CN.properties,其中\u7528这些是中文的Unicode编码
globe.properties
2、建立LongAction 类
什么都没有,直接返回successpackage com.java1234.action;import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return SUCCESS;
}
}
3、建立login.jsp文件
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <a href="lang.action?request_locale=zh_CN">中文</a><!--sturts2根据参数显示中文还是英文--> <a href="lang.action?request_locale=en_US">English</a> <br/><s:text name="welcomeInfo"> <s:param>Jack</s:param> </s:text> <table> <tr> <td><s:text name="userName"></s:text></td> <td> <input type="text"/> </td> </tr> <tr> <td><s:text name="password"></s:text></td> <td> <input type="text"/> </td> </tr> <tr> <td> <input type="button" value="<s:text name='login'></s:text>"/> </td> </tr> </table> </body> </html>
4、struts.xml里这样配置
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <!-- 下面这条就是关键,开启国际化功能 --> <constant name="struts.custom.i18n.resources" value="globe"></constant> <package name="login" extends="struts-default" namespace="/"> <action name="lang" class="action.LangAction"> <result >/login.jsp</result> </action> </package> </struts>
5、运行结果
相关文章推荐
- struts2国际化问题实例解析
- struts2的国际化(即实现网站整体中英文切换)实例
- Struts2国际化——完整实例代码
- struts2的国际化实现网站整体中英文切换实例代码
- Struts2国际化实例
- struts2(国际化) 项目实例
- struts2的国际化(即实现网站整体中英文切换)实例
- Struts2入门(10):国际化(i18n)和页面切换语言实例
- Struts2 国际化实例
- 由Spring管理的Struts2的Action的单实例问题
- struts2国际化支持
- Struts2国际化乱码问题解决
- Struts2 结合 Freemarker 实例
- struts2 结合extjs实现的一个登录实例
- Struts2学习——(二)开发实例-我的第一个Struts2工程
- Struts2与Freemarker整合实例
- Struts2 入门4 数据校验_类型转换_国际化
- Struts2 验证码图片实例
- struts2 mvc视图实例分析
- 使用Struts2(三)国际化