这是一作业。老师一时也想不出来。整个代码都是按照书上做的。也没有报错。只是在<script language="JavaScript">给了一个提示:invasion location of tag(script)。我也不知道是什么问题。接着在<script></script>中的代码都实现不了。总共做了四个jsp文件,一开始的登录页面login.jsp:
<%@ page contentType="text/html;charset=gb2312"%>
<script language="JavaScript">
function is Validate(form)
{
//得到的用户输入的信息
userid=form.userid.value;
userpass=form.userpass.value;
//判断用户名长度
if(!minLength(userid,6))
{
alert("用户名长度小于6位!");
form.userid.focus();
return false;
}
if(!maxLength(userid,8))
{
alert("用户名长度大于8位!");
form.userid.focus();
return false;
}
//判断口令长度
if(!minLength(userpass,6))
{
alert("口令长度小于6位!");
form.userpass.focus();
return false;
}
if(!maxLength(userpass,8))
{
alert("口令长度大于8位!");
form.userpass.focus();
return false;
}
//判断用户名和口令是否相同
if(userid=userpass)
{
alert("用户名和口令不能相同!");
form.userpass.focus();
return false;
}
return true;
}
// 验证是否满足最小长度
function minLength(str,length)
{
if(str.length>=length)
return true;
else
return true;
}
// 验证是否满足最大长度
function maxLength(str,length)
{
if(str.length<=length)
return true;
else
return true;
}
</script><html>
<head> <title>用户登录</title> </head>
<body>
<h2>用户登录</h2>
<form name="form1" action="login_process.jsp" method="post" onsubmit="return is Validate(form1)">
用户名:<input type="text" name="userid"><br>
口 令:<input type="password" name="userpass"><br>
<input type="reset" value="重置">
<input type="submit" value="提交"><br>
</form>
</body>
</html>和一个login_process.jsp文件:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><c:if test="${param.username==\"zhangsan\"&¶m.userpass==\"wangwu\"}">
<c:set var="username" value="${param.username}" scope="session"/>
<jsp:forward page="login_success.jsp"/>
</c:if><c:if test="${param.username!=\"zhangsan\"&¶m.userpass!=\"wangwu\"}">
<jsp:forward page="login_failure.jsp"/>
</c:if>login_success.jsp文件:
<%@ page contentType="text/html;charset=gb2312"%>
<html>
<head>
<title>登录成功</title>
</head>
<body>
<h2>${sessionScope.userid}您好,欢迎登录网上书店 !</h2>
</body>
</html>login_failure.jsp文件:
<%@ page contentType="text/html;charset=gb2312"%>
<html>
<head>
<title>登录失败</title>
</head>
<body>
<h2>用户名或者口令不正确,请<a href="login.jsp">重新登录</a></h2>
</body>
</html>求助
<%@ page contentType="text/html;charset=gb2312"%>
<script language="JavaScript">
function is Validate(form)
{
//得到的用户输入的信息
userid=form.userid.value;
userpass=form.userpass.value;
//判断用户名长度
if(!minLength(userid,6))
{
alert("用户名长度小于6位!");
form.userid.focus();
return false;
}
if(!maxLength(userid,8))
{
alert("用户名长度大于8位!");
form.userid.focus();
return false;
}
//判断口令长度
if(!minLength(userpass,6))
{
alert("口令长度小于6位!");
form.userpass.focus();
return false;
}
if(!maxLength(userpass,8))
{
alert("口令长度大于8位!");
form.userpass.focus();
return false;
}
//判断用户名和口令是否相同
if(userid=userpass)
{
alert("用户名和口令不能相同!");
form.userpass.focus();
return false;
}
return true;
}
// 验证是否满足最小长度
function minLength(str,length)
{
if(str.length>=length)
return true;
else
return true;
}
// 验证是否满足最大长度
function maxLength(str,length)
{
if(str.length<=length)
return true;
else
return true;
}
</script><html>
<head> <title>用户登录</title> </head>
<body>
<h2>用户登录</h2>
<form name="form1" action="login_process.jsp" method="post" onsubmit="return is Validate(form1)">
用户名:<input type="text" name="userid"><br>
口 令:<input type="password" name="userpass"><br>
<input type="reset" value="重置">
<input type="submit" value="提交"><br>
</form>
</body>
</html>和一个login_process.jsp文件:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><c:if test="${param.username==\"zhangsan\"&¶m.userpass==\"wangwu\"}">
<c:set var="username" value="${param.username}" scope="session"/>
<jsp:forward page="login_success.jsp"/>
</c:if><c:if test="${param.username!=\"zhangsan\"&¶m.userpass!=\"wangwu\"}">
<jsp:forward page="login_failure.jsp"/>
</c:if>login_success.jsp文件:
<%@ page contentType="text/html;charset=gb2312"%>
<html>
<head>
<title>登录成功</title>
</head>
<body>
<h2>${sessionScope.userid}您好,欢迎登录网上书店 !</h2>
</body>
</html>login_failure.jsp文件:
<%@ page contentType="text/html;charset=gb2312"%>
<html>
<head>
<title>登录失败</title>
</head>
<body>
<h2>用户名或者口令不正确,请<a href="login.jsp">重新登录</a></h2>
</body>
</html>求助
你把
<script language="JavaScript">
换成
<script language="JavaScript" type="text/javascript">
试试
1.
<html>
<head>
<Script Language = "JavaScript">
</Script>
</head>
</html>2.
<html>
<body>
<Script language = "JavaScript">
</Script>
</body>
</html>挪个地方吧。