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

你可能感兴趣的文章
nmap 使用总结
查看>>
nmap 使用方法详细介绍
查看>>
nmap使用
查看>>
nmap使用实战(附nmap安装包)
查看>>
Nmap哪些想不到的姿势
查看>>
Nmap扫描教程之Nmap基础知识
查看>>
nmap指纹识别要点以及又快又准之方法
查看>>
Nmap渗透测试指南之指纹识别与探测、伺机而动
查看>>
Nmap端口扫描工具Windows安装和命令大全(非常详细)零基础入门到精通,收藏这篇就够了
查看>>
NMAP网络扫描工具的安装与使用
查看>>
NMF(非负矩阵分解)
查看>>
nmon_x86_64_centos7工具如何使用
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>