博客
关于我
Struts使用包范围的国际化资源实战
阅读量:170 次
发布时间:2019-02-28

本文共 3049 字,大约阅读时间需要 10 分钟。

一 action

package org.crazyit.app.action;import com.opensymphony.xwork2.*;public class LoginAction extends ActionSupport{    // 下面定义了两个成员变量,用于封装请求参数    private String username;    private String password;    // username的setter和getter方法    public void setUsername(String username)    {        this.username = username;    }    public String getUsername()    {        return this.username;    }    // password的setter和getter方法    public void setPassword(String password)    {        this.password = password;    }    public String getPassword()    {        return this.password;    }    // 处理用户请求的execute方法    public String execute() throws Exception    {        ActionContext ctx = ActionContext.getContext();        if (getUsername().equals("crazyit.org")            && getPassword().equals("leegang"))        {            ctx.getSession().put("user" , getUsername());            // 获取国际化消息            ctx.put("tip" , getText("succTip"));            return SUCCESS;        }        else        {            // 获取国际化消息            ctx.put("tip" , getText("failTip"));            return ERROR;        }    }}

二 资源文件

1 package_zh_CN.properties

failTip=Package\u6d88\u606f\uff1a\u5bf9\u4e0d\u8d77\uff0c\u60a8\u4e0d\u80fd\u767b\u5f55\uff01succTip=Package\u6d88\u606f\uff1a\u6b22\u8fce\uff0c\u60a8\u5df2\u7ecf\u767b\u5f55\uff01username.required=Package\u6d88\u606f\uff1a\u7528\u6237\u540d\u662f\u5fc5\u9700\u7684\uff01

2 loginForm_zh_CN.properties

#\u5728JSP\u9875\u9762\u4f7f\u7528\u7684JSP\u8303\u56f4\u7684\u8d44\u6e90\u6587\u4ef6loginPage=JSP\u6d88\u606f\uff1a\u767b\u5f55\u9875\u9762errorPage=JSP\u6d88\u606f\uff1a\u9519\u8bef\u9875\u9762succPage=JSP\u6d88\u606f\uff1a\u6210\u529f\u9875\u9762failTip=JSP\u6d88\u606f\uff1a\u5168\u5c40\u6d88\u606f\uff1a\u5bf9\u4e0d\u8d77\uff0c\u60a8\u4e0d\u80fd\u767b\u5f55\uff01succTip=JSP\u6d88\u606f\uff1a\u5168\u5c40\u6d88\u606f\uff1a\u6b22\u8fce\uff0c\u60a8\u5df2\u7ecf\u767b\u5f55\uff01user=JSP\u6d88\u606f\uff1a\u7528\u6237\u540dpass=JSP\u6d88\u606f\uff1a\u5bc6  \u7801login=JSP\u6d88\u606f\uff1a\u767b\u5f55

3 result_en_US.properties

resultPage=Log In Result

三 校验文件

true

四 配置文件

/WEB-INF/content/loginForm.jsp
/WEB-INF/content/result.jsp
/WEB-INF/content/result.jsp
/WEB-INF/content/{1}.jsp

五 视图

1 loginForm.jsp

<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %><%@ taglib prefix="s" uri="/struts-tags"%>
<s:text name="loginPage"/>

2 result.jsp

<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %><%@ taglib prefix="s" uri="/struts-tags"%>
<s:text name="resultPage"/> ${requestScope.tip}

六 测试

 

转载地址:http://vsmj.baihongyu.com/

你可能感兴趣的文章
NFS安装配置
查看>>
NFS服务器配置-服务启动与停止
查看>>
NFS的安装以及windows/linux挂载linux网络文件系统NFS
查看>>
NFS的常用挂载参数
查看>>
NFS网络文件系统
查看>>
NFS远程目录挂载
查看>>
nft文件传输_利用remoting实现文件传输-.NET教程,远程及网络应用
查看>>
NFV商用可行新华三vBRAS方案实践验证
查看>>
ng build --aot --prod生成文件报错
查看>>
ng 指令的自定义、使用
查看>>
nghttp3使用指南
查看>>
Nginx
查看>>
nginx + etcd 动态负载均衡实践(一)—— 组件介绍
查看>>
nginx + etcd 动态负载均衡实践(三)—— 基于nginx-upsync-module实现
查看>>
nginx + etcd 动态负载均衡实践(二)—— 组件安装
查看>>
nginx + etcd 动态负载均衡实践(四)—— 基于confd实现
查看>>
Nginx + Spring Boot 实现负载均衡
查看>>
Nginx + Tomcat + SpringBoot 部署项目
查看>>
Nginx + uWSGI + Flask + Vhost
查看>>
Nginx - Header详解
查看>>