提交表单前验证 50
代码如下:<%@pagelanguage="java"import="java.util.*"pageEncoding="utf-8"%><%Stringpath=req...
代码如下:
<%@ 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">
-->
<script type="text/javascript">
//提交方法
function jurisdiction(jurisdiction,link)
{
alert("您没有权限,请登录。。。");
if (link==("manager/adduser.jsp"))
{
if (jurisdiction==("zero"))
{
alert("您没有权限,请登录。。。");
}
else if (jurisdiction==("one"))
{
alert("您没有权限,请登录。。。");
}
}
return true;
}
</script>
</head>
<body>
<form action="LoginServlet" method="post" onsubmit="return jurisdiction('${jurisdiction}','manager/adduser.jsp')">
<input type="hidden" name="jurisdiction" value="${jurisdiction}"/>
<input type="hidden" name="control" value="link"/>
<input type="hidden" name="link" value="manager/adduser.jsp"/>
<input type="submit" value="添加"/><br/>
</body>
</html>
我想在表单提交前运行方法,但是方法没有被执行 展开
<%@ 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">
-->
<script type="text/javascript">
//提交方法
function jurisdiction(jurisdiction,link)
{
alert("您没有权限,请登录。。。");
if (link==("manager/adduser.jsp"))
{
if (jurisdiction==("zero"))
{
alert("您没有权限,请登录。。。");
}
else if (jurisdiction==("one"))
{
alert("您没有权限,请登录。。。");
}
}
return true;
}
</script>
</head>
<body>
<form action="LoginServlet" method="post" onsubmit="return jurisdiction('${jurisdiction}','manager/adduser.jsp')">
<input type="hidden" name="jurisdiction" value="${jurisdiction}"/>
<input type="hidden" name="control" value="link"/>
<input type="hidden" name="link" value="manager/adduser.jsp"/>
<input type="submit" value="添加"/><br/>
</body>
</html>
我想在表单提交前运行方法,但是方法没有被执行 展开
2个回答
展开全部
验证一般都连接数据库的.这里只是作个示范.用户名:admin 密码:123
--------------------
login.html文件:
<html>
<head>
<title>登陆</title>
</head>
<script language="javascript">
function check()
{
if (document.form1.username.value=="")
{
document.getElementById("usernameTip").innerHTML="<font color=red>请输入用户名</font>";
document.form1.username.focus();
return false;
}
else
document.getElementById("usernameTip").innerHTML="";
if (document.form1.userpwd.value=="")
{
document.getElementById("userpwdTip").innerHTML="<font color=red>请输入密码</font>";
document.form1.userpwd.focus();
return false;
}
else
document.getElementById("userpwdTip").innerHTML="";
if (document.form1.username.value!="admin")//============用户名:admin =========
{
document.getElementById("ischeckTip").innerHTML="<font color=red>用户名不存在</font>";
document.form1.username.focus();
return false;
}
if (document.form1.userpwd.value!="123")//=======密码:123 =====
{
document.getElementById("ischeckTip").innerHTML="<font color=red>密码错误</font>";
document.form1.userpwd.focus();
return false;
}
return true;
}</script>
<body>
<form name="form1" method="post" action="index.html">
<table width="348" align="center" cellpadding="1" cellspacing="1" bgcolor="#99CCFF">
<tr>
<td width="59" bgcolor="#FFFFFF">用户名:</td>
<td width="105" bgcolor="#FFFFFF"><input name="username" type="text" size="15" bgcolor="#FFFFFF"></td>
<td width="174" id="usernameTip" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td bgcolor="#FFFFFF">密 码:</td>
<td bgcolor="#FFFFFF"><input name="userpwd" type="password" size="15" bgcolor="#FFFFFF"></td>
<td id="userpwdTip" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> </td>
<td bgcolor="#FFFFFF"><input type="submit" name="Submit1" value="提交" onClick="return check()">
<input type="reset" name="Submit2" value="重置"></td>
<td id="ischeckTip" bgcolor="#FFFFFF"> </td>
</tr>
</table>
</form>
</body>
</html>
------------------------------------------
index.html文件:
<html>
<head>
<title>欢迎</title>
</head>
<body>
登陆成功
</body>
</html>
以上回答你满意么?
--------------------
login.html文件:
<html>
<head>
<title>登陆</title>
</head>
<script language="javascript">
function check()
{
if (document.form1.username.value=="")
{
document.getElementById("usernameTip").innerHTML="<font color=red>请输入用户名</font>";
document.form1.username.focus();
return false;
}
else
document.getElementById("usernameTip").innerHTML="";
if (document.form1.userpwd.value=="")
{
document.getElementById("userpwdTip").innerHTML="<font color=red>请输入密码</font>";
document.form1.userpwd.focus();
return false;
}
else
document.getElementById("userpwdTip").innerHTML="";
if (document.form1.username.value!="admin")//============用户名:admin =========
{
document.getElementById("ischeckTip").innerHTML="<font color=red>用户名不存在</font>";
document.form1.username.focus();
return false;
}
if (document.form1.userpwd.value!="123")//=======密码:123 =====
{
document.getElementById("ischeckTip").innerHTML="<font color=red>密码错误</font>";
document.form1.userpwd.focus();
return false;
}
return true;
}</script>
<body>
<form name="form1" method="post" action="index.html">
<table width="348" align="center" cellpadding="1" cellspacing="1" bgcolor="#99CCFF">
<tr>
<td width="59" bgcolor="#FFFFFF">用户名:</td>
<td width="105" bgcolor="#FFFFFF"><input name="username" type="text" size="15" bgcolor="#FFFFFF"></td>
<td width="174" id="usernameTip" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td bgcolor="#FFFFFF">密 码:</td>
<td bgcolor="#FFFFFF"><input name="userpwd" type="password" size="15" bgcolor="#FFFFFF"></td>
<td id="userpwdTip" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> </td>
<td bgcolor="#FFFFFF"><input type="submit" name="Submit1" value="提交" onClick="return check()">
<input type="reset" name="Submit2" value="重置"></td>
<td id="ischeckTip" bgcolor="#FFFFFF"> </td>
</tr>
</table>
</form>
</body>
</html>
------------------------------------------
index.html文件:
<html>
<head>
<title>欢迎</title>
</head>
<body>
登陆成功
</body>
</html>
以上回答你满意么?
追问
我想知道我的代码错在哪里。可以的话请修改我的代码,满意加分
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询