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

你可能感兴趣的文章
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named 'pandads'
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
No static resource favicon.ico.
查看>>
no such file or directory AndroidManifest.xml
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>
NO.23 ZenTaoPHP目录结构
查看>>
no1
查看>>
NO32 网络层次及OSI7层模型--TCP三次握手四次断开--子网划分
查看>>
NOAA(美国海洋和大气管理局)气象数据获取与POI点数据获取
查看>>