在JSP里不能通过javascript的验证,而直接提交了表单!
怪了~看程序:<%@pagelanguage="java"import="java.util.*"pageEncoding="gb2312"%><%Stringpath=...
怪了~看程序:
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
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>register 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">
-->
<link href="./CSS/style.css" rel="stylesheet" type="text/css">
</head>
<script language="javascript">
function checkform(){
username=document.form1.user.value;
password=document.form1.pass.value;
password1=document.form1.pass1.value;
email=document.form1.ema.value;
if(username==""||username.length<6||username.lenght>15){
alert("用户名必须在6~15位之间");
return false;
}
if(!((username>'a'&&username<'z')||(username>'A'&&username<'Z'))){
alert("用户名必须为字母!");
return false;
}
if(password!=password1){
alert("密码不匹配!");
return false;
}
if(email==""||(email.indexOf('@')==-1)||(email.indexOf('.')==-1)){
alert("EMAIL格式不对!");
return false;
}
return true;
}
</script>
<body>
<div id="container">
<div id="banner">
<img src="./img/banner.jpg" width="789" height="177">
</div>
<form action="./WebRoot/aduser.jsp" method="get" name="from1" onSubmit="retrun checkform()">
<table width="500" height="200" border="0" align="center">
<tr>
<td colspan="2" align="center">
用户注册
</td>
</tr>
<tr>
<td align="letf">
用户名:
</td>
<td>
<input name="user" type="text" value="">
*用户名为6~15字母
</td>
</tr>
<tr>
<td align="left">
密 码:
</td>
<td>
<input name="pass" type="password" value="">
*密码在3位以上
</td>
</tr>
<tr>
<td align="left">
密码确认:
</td>
<td>
<input name="pass1" type="password" value="">
*
</td>
</tr>
<tr>
<td align="left">
邮 箱:
</td>
<td>
<input name="ema" type="text" value="">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="Submit" value="确定" >
<input type="reset" name="reset" value="重填">
</td>
</tr>
</table>
</form>
</body>
</html>
程序改好\运行好后发布出来~谢了~加高分~ 展开
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
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>register 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">
-->
<link href="./CSS/style.css" rel="stylesheet" type="text/css">
</head>
<script language="javascript">
function checkform(){
username=document.form1.user.value;
password=document.form1.pass.value;
password1=document.form1.pass1.value;
email=document.form1.ema.value;
if(username==""||username.length<6||username.lenght>15){
alert("用户名必须在6~15位之间");
return false;
}
if(!((username>'a'&&username<'z')||(username>'A'&&username<'Z'))){
alert("用户名必须为字母!");
return false;
}
if(password!=password1){
alert("密码不匹配!");
return false;
}
if(email==""||(email.indexOf('@')==-1)||(email.indexOf('.')==-1)){
alert("EMAIL格式不对!");
return false;
}
return true;
}
</script>
<body>
<div id="container">
<div id="banner">
<img src="./img/banner.jpg" width="789" height="177">
</div>
<form action="./WebRoot/aduser.jsp" method="get" name="from1" onSubmit="retrun checkform()">
<table width="500" height="200" border="0" align="center">
<tr>
<td colspan="2" align="center">
用户注册
</td>
</tr>
<tr>
<td align="letf">
用户名:
</td>
<td>
<input name="user" type="text" value="">
*用户名为6~15字母
</td>
</tr>
<tr>
<td align="left">
密 码:
</td>
<td>
<input name="pass" type="password" value="">
*密码在3位以上
</td>
</tr>
<tr>
<td align="left">
密码确认:
</td>
<td>
<input name="pass1" type="password" value="">
*
</td>
</tr>
<tr>
<td align="left">
邮 箱:
</td>
<td>
<input name="ema" type="text" value="">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="Submit" value="确定" >
<input type="reset" name="reset" value="重填">
</td>
</tr>
</table>
</form>
</body>
</html>
程序改好\运行好后发布出来~谢了~加高分~ 展开
2个回答
展开全部
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
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>register 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">
-->
<link href="./CSS/style.css" rel="stylesheet" type="text/css">
</head>
<script language="javascript">
function checkform(){
username=document.form1.user.value;
password=document.form1.pass.value;
password1=document.form1.pass1.value;
email=document.form1.ema.value;
if(username==""||username.length<6||username.lenght>15){
alert("用户名必须在6~15位之间");
return false;
}
else if(!((username>'a'&&username<'z')||(username>'A'&&username<'Z'))){
alert("用户名必须为字母!");
return false;
}
else if(password!=password1){
alert("密码不匹配!");
return false;
}
else if(email==""||(email.indexOf('@')==-1)||(email.indexOf('.')==-1)){
alert("EMAIL格式不对!");
return false;
}else{
return true;}
}
</script>
<body>
<div id="container">
<div id="banner">
<img src="./img/banner.jpg" width="789" height="177">
</div>
<form action="./WebRoot/aduser.jsp" method="get" name="from1" onSubmit="retrun checkform()">
<table width="500" height="200" border="0" align="center">
<tr>
<td colspan="2" align="center">
用户注册
</td>
</tr>
<tr>
<td align="letf">
用户名:
</td>
<td>
<input name="user" type="text" value="">
*用户名为6~15字母
</td>
</tr>
<tr>
<td align="left">
密 码:
</td>
<td>
<input name="pass" type="password" value="">
*密码在3位以上
</td>
</tr>
<tr>
<td align="left">
密码确认:
</td>
<td>
<input name="pass1" type="password" value="">
*
</td>
</tr>
<tr>
<td align="left">
邮 箱:
</td>
<td>
<input name="ema" type="text" value="">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="Submit" value="确定" >
<input type="reset" name="reset" value="重填">
</td>
</tr>
</table>
</form>
</body>
</html>
改成这样试试。
<%
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>register 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">
-->
<link href="./CSS/style.css" rel="stylesheet" type="text/css">
</head>
<script language="javascript">
function checkform(){
username=document.form1.user.value;
password=document.form1.pass.value;
password1=document.form1.pass1.value;
email=document.form1.ema.value;
if(username==""||username.length<6||username.lenght>15){
alert("用户名必须在6~15位之间");
return false;
}
else if(!((username>'a'&&username<'z')||(username>'A'&&username<'Z'))){
alert("用户名必须为字母!");
return false;
}
else if(password!=password1){
alert("密码不匹配!");
return false;
}
else if(email==""||(email.indexOf('@')==-1)||(email.indexOf('.')==-1)){
alert("EMAIL格式不对!");
return false;
}else{
return true;}
}
</script>
<body>
<div id="container">
<div id="banner">
<img src="./img/banner.jpg" width="789" height="177">
</div>
<form action="./WebRoot/aduser.jsp" method="get" name="from1" onSubmit="retrun checkform()">
<table width="500" height="200" border="0" align="center">
<tr>
<td colspan="2" align="center">
用户注册
</td>
</tr>
<tr>
<td align="letf">
用户名:
</td>
<td>
<input name="user" type="text" value="">
*用户名为6~15字母
</td>
</tr>
<tr>
<td align="left">
密 码:
</td>
<td>
<input name="pass" type="password" value="">
*密码在3位以上
</td>
</tr>
<tr>
<td align="left">
密码确认:
</td>
<td>
<input name="pass1" type="password" value="">
*
</td>
</tr>
<tr>
<td align="left">
邮 箱:
</td>
<td>
<input name="ema" type="text" value="">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="Submit" value="确定" >
<input type="reset" name="reset" value="重填">
</td>
</tr>
</table>
</form>
</body>
</html>
改成这样试试。
展开全部
我刚刚帮你改了,真的是气得我半死!!
首先你的字母写错,(最低级的错误)!!!!
1,
在javaScript中:
username=document.form1.user.value;
在html中:
<form action="./WebRoot/aduser.jsp" method="get" name="from1" onSubmit="retrun checkform()">
睁大眼睛看好了,你form的命名.
脚本里面是form1,HTML中是from1,靠!
2,
然后你函数的调用,就是onSubmit="retrun checkform()"
仔细看看,什么retrun啊,写成return
3,你的命名问题
看这句
username=document.form1.user.value;
user在脚本中属于关键字,不能用,你要改成其他的名字,
记得在脚本中改了以后,对应的HTML中也要把名字给改过来..
就这3点,以后写程序的时候细心一点.
首先你的字母写错,(最低级的错误)!!!!
1,
在javaScript中:
username=document.form1.user.value;
在html中:
<form action="./WebRoot/aduser.jsp" method="get" name="from1" onSubmit="retrun checkform()">
睁大眼睛看好了,你form的命名.
脚本里面是form1,HTML中是from1,靠!
2,
然后你函数的调用,就是onSubmit="retrun checkform()"
仔细看看,什么retrun啊,写成return
3,你的命名问题
看这句
username=document.form1.user.value;
user在脚本中属于关键字,不能用,你要改成其他的名字,
记得在脚本中改了以后,对应的HTML中也要把名字给改过来..
就这3点,以后写程序的时候细心一点.
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询