input_user.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
<form action="reg.action" method="post">
用户编号: <input name="user.uid" /> <br/>
用户名: <input name="user.uname" /><br/>
密码: <input name="user.password" /><br/>
年龄: <input name="user.age" /><br/>
出生日期: <input name="user.birthday"/><br/>
邮箱: <input name="user.email"/><br/>
<input type="submit" value="注册"/>
</form>
</body>
</html>

  

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="p" namespace="/" extends="struts-default">
<action name="reg" class="com.etc.action.RegAction">
<result>
/showuser.jsp
</result>
<result name="input">
/showerror.jsp
</result>
</action>
</package>
</struts>

  

showuser.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'show.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head> <body>
注册成功!用户信息如下: ${user }
</body>
</html>

  

showerror.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'showerror.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head> <body>
出错信息如下:<s:fielderror/>
</body>
</html>

  

package com.etc.entity;

import java.util.Date;

public class User {
private Integer uid;
private String uname;
private String password;
private Integer age;
private Date birthday;
private String email; public Integer getUid() {
return uid;
}
public void setUid(Integer uid) {
this.uid = uid;
}
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
} public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public String toString() {
return "User [age=" + age + ", birthday=" + birthday + ", email="
+ email + ", password=" + password + ", uid=" + uid
+ ", uname=" + uname + "]";
}
}

  

RegAction  :

package com.etc.action;

import java.util.Date;

import com.etc.entity.User;
import com.opensymphony.xwork2.ActionSupport; public class RegAction extends ActionSupport
{
private User user; public User getUser() {
return user;
} public void setUser(User user) {
this.user = user;
} public String execute()
{
return "success";
}
}

  

RegAction-validation.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC
"-//Apache Struts//XWork Validator 1.0.2//EN"
"http://struts.apache.org/dtds/xwork-validator-1.0.2.dtd">
<validators>
<validator type="required"><!-- 必填字段 -->
<param name="fieldName">user.uid</param>
<message>uid不能为空</message>
</validator> <validator type="required">
<param name="fieldName">user.age</param>
<message>年龄不能为空</message>
</validator> <validator type="requiredstring"> <!-- 必填字符串校验 -->
<param name="fieldName">user.uname</param>
<message>用户名不能为空</message>
</validator> <validator type="requiredstring"> <!-- 必填字符串校验 -->
<param name="fieldName">user.password</param>
<message>密码不能为空</message>
</validator> <validator type="int"> <!-- 整数校验器 -->
<param name="fieldName">user.age</param>
<param name="max">120</param>
<param name="min">0</param>
<message>年龄必须在${min}-${max}之间!</message>
</validator>
<validator type="stringlength"> <!--字符串长度校验器,根据字符数 -->
<param name="fieldName">user.password</param>
<param name="maxLength">20</param>
<param name="minLength">6</param>
<message>密码长度必须在${minLength}-${maxLength}之间!</message>
</validator> <validator type="date"> <!--字符串长度校验器,根据字符数 -->
<param name="fieldName">user.birthday</param>
<param name="max">2016-1-1</param>
<param name="min">1980-1-1</param>
<message>生日必须在${min}-${max}之间!</message>
</validator>
<validator type="email"> <!--字符串长度校验器,根据字符数 -->
<param name="fieldName">user.email</param>
<message>邮箱非法!</message>
</validator> <validator type="myusername">
<param name="fieldName">user.uname</param>
<message>用户名不能含有中文!</message>
</validator>
</validators>

  

数据校验(3)--demo2---bai的更多相关文章

  1. struts2:数据校验,通过Action中的validate()方法实现校验,图解

    根据输入校验的处理场所的不同,可以将输入校验分为客户端校验和服务器端校验两种.服务器端验证目前有两种方式: 第一种 Struts2中提供了一个com.opensymphony.xwork2.Valid ...

  2. WPF---数据绑定之ValidationRule数据校验(六)

    一.概述 我们知道,Binding好比架设在Source和Target之间的桥梁,数据可以借助这个桥梁进行流通.在数据流通的过程中,我们可以在Binding这座桥梁上设置关卡,对数据的有效性进行验证. ...

  3. Struts2数据校验

    Struts2数据校验 1.常见数据校验方法 表单数据的校验方式: 表单中的数据必须被效验以后才能够被使用,常用的效验方式分为两种: 前台校验:也称之为客户端效验,主要是通过JS编程的方式进行表单数据 ...

  4. Spring MVC数据校验

    在web应用程序中,为了防止客户端传来的数据引发程序异常,常常需要对 数据进行验证.输入验证分为客户端验证与服务器端验证.客户端验证主要通过JavaScript脚本进行,而服务器端验证则主要通过Jav ...

  5. spring mvc 数据校验

    1.需要导入的jar包: slf4j-api-1.7.21.jar validation-api-1.0.0.GA.jar hibernate-validator-4.0.1.GA.jar 2.访问页 ...

  6. SpringMvc中的数据校验

    SpringMvc中的数据校验 Hibernate校验框架中提供了很多注解的校验,如下: 注解 运行时检查 @AssertFalse 被注解的元素必须为false @AssertTrue 被注解的元素 ...

  7. springmvc的数据校验

       springmvc的数据校验 在Web应用程序中,为了防止客户端传来的数据引发程序异常,常常需要对数据进行验证,输入验证分为客户端验证与服务器端验证. 客户端验证主要通过javaScript脚本 ...

  8. Struts 2 数据校验要用到的类和两种校验方式以及一些校验问题的解决

    通过继承ActionSupport类来完成Action开发,ActionSupport类不仅对Action接口进行简单实现, 同时增加了验证.本地化等支持 .真实开发中自定义Action都需要继承该类 ...

  9. Struts 2的数据校验

    既然说到了Struts 2的数据校验,我们该怎么去实现呢?又是通过什么来实现呢? 就让我带着大家一起来走进Struts 2的数据校验吧. 首先我们会想到在Stuts 2的登录案例中我们定义了一个Act ...

  10. 使用Struts2实现数据校验

    使用Struts2实现数据校验 为什么需要数据校验呢?答案很简单,假如当你登录想要京东,这时就需要数据校验了如果不输入用户名的话,那么就不会登陆成功,并且会提示出"请输入用户名"的 ...

随机推荐

  1. Shell脚本报错--syntax error near unexpected token for((i=0;i<$length;i++))

    现象: shell脚本使用Nodepad++进行本地编辑,在编辑后上传到linux机器进行执行时提示“syntax error near unexpected token for((i=0;i< ...

  2. Linux嵌入式 -- 内核 - 进程控制 和 调度

    1. 进程四要素 1. 有一段程序供其执行.这段程序不一定是某个进程所专有,可以与其他进程共用. 2. 有进程专用的内核空间堆栈. 3. 在内核中有一个task_struct数据结构,即通常所说的&q ...

  3. 代码题(59)— 字符串相加、字符串相乘、打印最大n位数

    1.415. 字符串相加 给定两个字符串形式的非负整数 num1 和num2 ,计算它们的和. 思路:和链表相加类似,求进位. class Solution { public: string addS ...

  4. webdriver处理鼠标右键菜单栏

    selenium中ActionChains类提供了鼠标操作的常用方法,但对于鼠标右键的菜单栏,无论是send_keys(Keys.ARROW_DOWN)还是send_keys("K" ...

  5. LightOJ - 1104 概率

    题意:每年n天,求最少几个人使这些人中最少两个人生日相同的概率大于0.5 题解:直接递推,假设有k个人,所有情况为n^k,没有相同的情况为n*(n-1)*...*(n-k+1),可以算出1e5以内不超 ...

  6. poj2112 最大流+floyd+二分

    题意:给一堆点,一部分是牛,一部分是机器,每头牛必须要走到一个机器,每个点之间有距离,要求每头牛都能找得到一台机器(机器有最大容量)的情况下,走的最远的牛距离最小 题解:二分答案,小于该距离的边才能加 ...

  7. OpenStack H版与 Ceph 整合的现状

    转自:https://www.ustack.com/blog/openstack_and_ceph/ Contents 1 Ceph与Nova整合 2 Ceph与Cinder整合 3 相关Patch ...

  8. deep learning (五)线性回归中L2范数的应用

    cost function 加一个正则项的原因是防止产生过拟合现象.正则项有L1,L2 等范数,我看过讲的最好的是这个博客上的:机器学习中的范数规则化之(一)L0.L1与L2范数.看完应该就答题明白了 ...

  9. [转载]java读写word文档,完美解决方案

    做项目的过程中,经常需要把数据里里的数据读出来,经过加工,以word格式输出. 在网上找了很多解决方案都不太理想,偶尔发现了PageOffice,一个国产的Office插件,开发调用非常简单!比网上介 ...

  10. Tomcat_总结_01_tomcat环境搭建

    一.准备条件 1.安装jdk 二.安装tomcat 1.下载tomcat 去官网下载  64-bit Windows zip  版本的tomcat,并解压 https://tomcat.apache. ...