20171113_chr_logini18n 登陆页面初步国际化(Action范围与资源文件)

来源:互联网 发布:淘宝德军后勤部 编辑:程序博客网 时间:2024/06/08 16:26

登陆页面初步国际化

  • /20171113_chr_logini18n/src/nuc/sw/action/LoginAction.java
package nuc.sw.action;import java.util.regex.Pattern;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport {    //属性驱动校验    private String username;    private String password;    public String getUsername() {      return username;    }    public void setUsername(String username) {      this.username = username;    }    public String getPassword() {      return password;    }    public void setPassword(String password) {      this.password = password;    }    //手动检验    @Override    public void validate() {    // TODO Auto-generated method stub    //进行数据校验,长度6~15位           if(username.trim().length()<6||username.trim().length()>15||username==null)         {            this.addFieldError("username", "用户名长度不合法!");        }        if(password.trim().length()<6||password.trim().length()>15||password==null)         {            this.addFieldError("password", "密码长度不合法!");        }    }    //登陆业务逻辑    public String loginMethod() {        if(username.equals("chenghaoran")&&password.equals("12345678")) {            ActionContext.getContext().getSession().put("user", username);            return "loginOK";        }else {            this.addFieldError("err",this.getText("errorInfo"));            return "loginFail";        }    }    //手动校验validateXxx    public void validateLoginMethod() {        //使用正则校验        if(username==null||username.trim().equals("")) {            this.addFieldError("username",this.getText("user.required"));        }else {            if(!Pattern.matches("[a-zA-Z]{6,15}", username.trim())) {                this.addFieldError("username", "用户名格式错误!");            }        }        if(password==null||password.trim().equals("")) {            this.addFieldError("password",this.getText("pass.required"));        }else {            if(!Pattern.matches("\\d{6,15}", password.trim())) {                this.addFieldError("password", "密码格式错误!");            }        }    }}
  • /20171113_chr_logini18n/src/nuc/sw/action/LoginAction_en_US.properties
user.required=username is required!pass.required=password is required!errorInfo=Username or password is error!
  • /20171113_chr_logini18n/src/nuc/sw/action/LoginAction_zh_CN.properties
user.required=\u7528\u6237\u540D\u4E0D\u80FD\u4E3A\u7A7A\uFF01pass.required=\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A\uFF01errorInfo=\u7528\u6237\u540D\u6216\u5BC6\u7801\u9519\u8BEF\uFF01
  • /20171113_chr_logini18n/src/nuc/sw/i18n/login_en_US.properties
title=Login Pageuser=usernamepass=passwordsubmit=login
  • /20171113_chr_logini18n/src/nuc/sw/i18n/login_zh_CN.properties
title=\u767B\u5F55\u9875\u9762user=\u7528\u6237\u540Dpass=\u5BC6\u7801submit=\u767B\u9646
  • /20171113_chr_logini18n/src/struts.xml
<struts>    <constant name="struts.custom.i18n.resources" value="message"></constant>     <!-- Add packages here -->    <package name="Login" namespace="/" extends="struts-default">      <action name="loginAction" class="nuc.sw.action.LoginAction" method="loginMethod">       <result name="loginOK">        /welcome.jsp       </result>       <result name="loginFail">        /login.jsp       </result>       <result name="input">        /login.jsp       </result>      </action>     </package></struts>
  • /20171113_chr_logini18n/WebContent/login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><%@ taglib prefix="s" uri="/struts-tags" %>    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><s:i18n name="nuc.sw.i18n.login"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title><s:text name="title"></s:text></title></head><body>  <s:fielderror fieldName="err"></s:fielderror>  <s:form action="loginAction" method="post">     <s:textfield name="username" key="user"></s:textfield>    <s:password  name="password" key="pass"></s:password>    <s:submit key="submit"></s:submit>  </s:form></body></html></s:i18n>
  • /20171113_chr_logini18n/WebContent/welcome.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>欢迎页</title></head><body>  欢迎${sessionScope.user}登陆!</body></html>
阅读全文
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 孩子不爱写作文怎么办 写作文没有素材怎么办 写作文没有灵感怎么办 做事工作马虎粗心大意怎么办 小孩作业马虎粗心大意怎么办 孩子写字一直错怎么办 孩子写字老错怎么办 写错字涂黑了怎么办 写错字不能涂改怎么办 孩子爱写错别字怎么办 孩子读题马虎怎么办 孩子知错不该怎么办 小孩胆小反应慢怎么办 孩孑经常流鼻血怎么办 中考考号写错了怎么办 头后仰就头晕怎么办 感觉自己要晕倒怎么办 孩子不愿动手写字怎么办 老年人恶心想吐怎么办 小学生老写错别字怎么办 突然头晕站不稳 怎么办 早上起床突然天旋地转怎么办 躺着突然感觉天旋地转怎么办 眩晕症发作时怎么办 低血糖恶心想吐怎么办 更年期头晕头胀怎么办 年轻人头晕头胀怎么办 教案:《眯眼了怎么办》 迷路了怎么办活动意图 幼儿迷路了怎么办图片 中班迷路了怎么办教案 大门与大门相对怎么办 孩子长倒睫毛怎么办 孩子考倒数第一怎么办 孩子在班里倒数怎么办 宝宝不用吸管杯怎么办 婴儿发烧37.6度怎么办 宝宝体温37.2度怎么办 宝宝发烧37.2度怎么办 宝宝半夜37.2度怎么办 宝宝发热不退热怎么办