博客
关于我
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/

你可能感兴趣的文章
Nginx学习总结(13)——Nginx 重要知识点回顾
查看>>
Nginx学习总结(14)——Nginx配置参数详细说明与整理
查看>>
Nginx安装与常见命令
查看>>
Nginx安装及配置详解
查看>>
Nginx实战经验分享:从小白到专家的成长历程!
查看>>
Nginx实现反向代理负载均衡
查看>>
nginx实现负载均衡
查看>>
nginx开机启动脚本
查看>>
nginx异常:the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf
查看>>
nginx总结及使用Docker创建nginx教程
查看>>
nginx报错:the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:128
查看>>
nginx报错:the “ssl“ parameter requires ngx_http_ssl_module in usrlocalnginxconfnginx.conf128
查看>>
nginx日志分割并定期删除
查看>>
Nginx日志分析系统---ElasticStack(ELK)工作笔记001
查看>>
Nginx映射本地json文件,配置解决浏览器跨域问题,提供前端get请求模拟数据
查看>>
nginx最最最详细教程来了
查看>>
Nginx服务器---正向代理
查看>>
Nginx服务器上安装SSL证书
查看>>
Nginx服务器的安装
查看>>
Nginx模块 ngx_http_limit_conn_module 限制连接数
查看>>