struts2实现国际化
来源:互联网 发布:富爸爸买卖贵金属 知乎 编辑:程序博客网 时间:2024/06/05 17:54
案例:
在src目录下新建两个属性文件:
welcome_en_US.properties:
greeting=Welcome to china\!
welcome_zh_CN.properties:
greeting=欢迎来到中国
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="welcome"></constant></struts>
index.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><%@ taglib uri="/struts-tags" prefix="s" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> </head> <body> <s:text name="greeting"></s:text> </body></html>
在action中访问资源文件:
User.java:
package blog.i18n;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;public class User extends ActionSupport {public String execute(){ActionContext.getContext().put("wel", this.getText("greeting"));return "success";}}
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="welcome"></constant><package name="i18n" extends="struts-default" namespace="/person"><action name="nation" class="blog.i18n.User" method="execute"><result name="input">/index.jsp</result><result name="success">/WEB-INF/message.jsp</result></action></package></struts>
message.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><%@ taglib uri="/struts-tags" prefix="s" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> </head> <body> <s:text name="greeting"></s:text> <br/> <%= request.getAttribute("wel") %> </body></html>
- struts2实现国际化
- struts2实现国际化
- struts2实现国际化
- struts2国际化实现过程
- Struts2 的国际化实现
- Struts2 的国际化实现
- Struts2 的国际化实现
- Struts2 的国际化实现
- Struts2 的国际化实现
- Struts2实现国际化
- Struts2的国际化实现
- Struts2 的国际化实现
- struts2实现国际化
- Struts2 本地化/国际化实现
- struts2实现国际化
- Struts2 的国际化实现
- struts2 用户自定义实现国际化
- 国际化之struts2实现研究
- 水晶报表好的博客园
- Websharp 个人记录
- VS 2012 C++程序将支持Windows XP (这篇文章害我浪费了一整天的时间查问题)
- chrome下img加载对height()的影响
- 套接字选项setsockopt()
- struts2实现国际化
- String类型的数据的操作
- 初识vb数据库最常用的两个对象(ADO Recordset 和 ADO Connection)
- California Mathmetics-G6-Ch1
- 新浪微博系统 Xweibo v1.1.1beta 免费版Xweibo-Xweibo 软件系统简介(PHP+MYSQL)
- poi 操作excel 生成超链接
- php中gd库作图函数
- 分享个谷歌地图API实现多标签(多marker),带分页
- OpenGL ES 模型视图之缩放操作