下面是用script来验证登录程序代码,其中有些我不理解,我是引用的.达不到效果,
还望大家多多指点,有错的地方请指出来,谢谢
<%@ page contentType="text/html;charset=gb2312" %>
<%@page import="java.sql.*"%>
<html><body bgcolor=pink><font>
<head>
<title>登陆</title>
</head>
<center>
<h1>实验室设备管理系统</h1>
<br>
<br>
<form name="login" action="loginconf.jsp" method="post">
<script language="javascript">
function setlg()
{
document.login.umame.focus();
document.login.upassword.focus();
}
function selec(txt)
{
txt.focus();
txt.select();
}
function chkuname(txt)//检查帐号
{
var nam=document.login.uname;
if(nam.value=="")
{
alert("请输入用户名!");
return false;
}else{
return true;
}
}
function chkupassword()//检查密码
{
var pw=document.login.upassword;
if(pw.value=="")
{
alert("请输入密码!");
return false;
}else{
return true;
}
}</script>
<table>
<tr><center><td>用户登陆</td>
</tr>
<tr>
<td>用户名:</td>
<td><input type="text" name="uname"</td>
</tr>
<tr>
<td>密  码:</td>
<td><input type="password" name="upassword"></td>
</tr>
<tr>
<td>
<input type="submit" value="登陆">
<input type="reset" value="重置">
<a href ="chpwd.jsp">修改密码</a>
</td>
</tr>
</table>
</form>
</center>
</font></body></html>
还望大家多多指点,有错的地方请指出来,谢谢
<%@ page contentType="text/html;charset=gb2312" %>
<%@page import="java.sql.*"%>
<html><body bgcolor=pink><font>
<head>
<title>登陆</title>
</head>
<center>
<h1>实验室设备管理系统</h1>
<br>
<br>
<form name="login" action="loginconf.jsp" method="post">
<script language="javascript">
function setlg()
{
document.login.umame.focus();
document.login.upassword.focus();
}
function selec(txt)
{
txt.focus();
txt.select();
}
function chkuname(txt)//检查帐号
{
var nam=document.login.uname;
if(nam.value=="")
{
alert("请输入用户名!");
return false;
}else{
return true;
}
}
function chkupassword()//检查密码
{
var pw=document.login.upassword;
if(pw.value=="")
{
alert("请输入密码!");
return false;
}else{
return true;
}
}</script>
<table>
<tr><center><td>用户登陆</td>
</tr>
<tr>
<td>用户名:</td>
<td><input type="text" name="uname"</td>
</tr>
<tr>
<td>密  码:</td>
<td><input type="password" name="upassword"></td>
</tr>
<tr>
<td>
<input type="submit" value="登陆">
<input type="reset" value="重置">
<a href ="chpwd.jsp">修改密码</a>
</td>
</tr>
</table>
</form>
</center>
</font></body></html>
1.在action处
<form action="" method="post" onsubmit="chkuname(); chkupassword();";>
... ...
</form>
2.在提交按钮处
<input type="submit" onsubmit="chkuname(); chkupassword();";>" value="登陆"/>
或者
<input type="submit" onclick="chkuname(); chkupassword();";>" value="登陆"/>
另外
建议写在一个fuction即可
1.在action处
<form action="" method="post" onsubmit="chkuname(); chkupassword();">
... ...
</form>
2.在提交按钮处
<input type="submit" onsubmit="chkuname(); chkupassword();">" value="登陆"/>
或者
<input type="submit" onclick="chkuname(); chkupassword();">" value="登陆"/>
另外
建议写在一个fuction即可
function chkupassword()//检查密码的时候
因为方法中采取了return true ;return false的返回值
所以也可以这样调用
<input type="submit" onclick="return chkuname()" value="登陆"/>
返回true时提交,否则不提交
<html>
<head>
<script language="javascript">
function a(){
if(document.all.UserName==""){
alert("请输入用户名");
return false;
}
if(document.all.Password==""){
alert("请输入密码");
return false;
}
window.xx.submit.click(); //直接提交表单中的用户名,密码
}</script>
</head>
<body>
<form name="xx" action=create.jsp method="post"> //create.jsp为处理页 方法为
<table>
<input type=text name="UserName" value="" >用户名
<input type=password name="Password" value="">用户密码 //这样显示出的密码是****的格式
<input type="submit" onclick="a();"
</table>
</form>
</html>
验证用户名是否重复,建议在你数据库中以用户名作为主键,直接避免了重复用户名的发生。
function setlg()
{
document.login.umame.focus();
document.login.upassword.focus();
}
function selec(txt)
{
txt.focus();
txt.select();
}
function chkuname(txt)//检查帐号
{
var nam=document.login.uname;
if(nam.value=="")
{
alert("请输入用户名!");
return false;
}else{
return true;
}
}
function chkupassword()//检查密码
{
var pw=document.login.upassword;
if(pw.value=="")
{
alert("请输入密码!");
return false;
}else{
return true;
}
} </script> 这段代码应该放在前面。
因为浏览器是解释性顺序执行html,所以,如果你的脚本在form后面,而form的验证就可能找不到验证函数了。
<head>
<title> Demo version </title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="Author" content="[email protected]">
<script>
function checkForm( obj_form ){
if( obj_form.uNice.value.length < 1 ){
alert( 'User Is Empty.' );
obj_form.uNice.focus();
return false;
}
if( obj_form.uNice.value.length < 8 ){
alert( 'User Nice Too Short.' );
obj_form.uNice.focus();
return false;
}
if( obj_form.uPass.value.length < 1 ){
alert( 'Password Is Empty.' );
obj_form.uPass.focus();
return false;
}
alert( 'Check OK!' );
return true;
}
</script>
</head><body>
<form onsubmit='return checkForm(this);'>
User:<input type='text' name='uNice' /><br />
Pass:<input type='password' name='uPass' /><br />
<input type='submit' value='Enter'>
</form>
</body>
</html>
先写一个javabean连接数据库,在这个jsp文件里引入那个javabean.
然后读取用户输入的账号和密码;从数据库中读取该帐号对应的密码,将其余用户输入的密码进行比较,一样的话,
就登陆成功,返回另一个页面。