<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>用户添加</title>
<script src="http://lib.sinaapp.com/js/jquery/2.0.2/jquery-2.0.2.min.js">
</script>
<script type="text/javascript">
function check(form){
if(form.userName.value==""){
alert("请输入用户名,不可为空!");
form.userName.focus();
return false;
}
if(form.password.value==""){
alert("请输入密码,不可为空!");
form.password.focus();
return false;
}
if(isNaN()){
alert("请输入整数年龄!")
form.age.focus();
return false;
}
}
</script>
</head>
<body >
<h1 align="center">用户添加界面</h1>
<form action="<%=path %>/user/save.do" method="post" id="formTable" name="form1" >
<table align="center">
<tr>
<td><input type="hidden" readonly="readonly" id="inputid" name="id" value="${user.id }" /></td>
</tr>
<tr>
<td>用户名:</td>
<td><input type="text" id="userName" name="userName" value="${user.userName }" /></td>
<td>(*不可为空*)</td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" id="password" name="password" value="${user.password }" /></td>
<td>(*不可为空*)</td>
</tr>
<tr>
<td>年龄:</td>
<td><input type="text" id="age" name="age" size="2" value="${user.age }" /></td>
</tr>
<tr>
<td><input type="submit" id="submit1" value="保存" onclick="return check(this.form);"/></td>
<td>
<a href="user/userlist.do">
<button type="button">返回</button>
</a>
</td>
</tr>
</table>
</form>
</body>
</html>
^[0-9]*$ 用正则校验
if(isNaN(form.age.value)){
alert("请输入整数年龄!")
form.age.focus();
return false;
}