首先是提交页面:三个表单(form1,form2,form3)
<form name="form1" method="post" action="checklogin.jsp" class="niceform">
<input name="qx" type="hidden" value="3">
<label for="textinput">帐号:</label>
<input type="text" id="textinput" name="uid" size="12" />
<br />
<label for="passwordinput">密码:</label>
<input type="password" id="passwordinput" name="pwd" size="12" />
<br />
<input name="" type="submit" value="提交">
<input type="reset" name="Submit2" value="重置" />
</form>
</div>
<div class=tagContent id=tagContent1>欢迎使用本系统,请先【登陆】或【注册】。
<form name="form2" method="post" action="checklogin.jsp" class="niceform">
<input name="qx" type="hidden" value="2">
<label for="textinput">帐号:</label>
<input type="text" id="textinput" name="uid" size="12" />
<br />
<label for="passwordinput">密码:</label>
<input type="password" id="passwordinput" name="pwd" size="12" />
<br />
<input name="Submit1" type="submit" id="Submit1" value="提交" />
<input type="reset" name="Submit2" value="重置" />
</form>
</div>
<div class=tagContent id=tagContent2>欢迎使用本系统,请先【登陆】然后进行管理。
<form name="form3" method="post" action="admin/checklogin.jsp" class="niceform">
<input name="qx" type="hidden" value="1">
<label for="textinput">帐号:</label>
<input type="text" id="textinput" name="uid" size="12" />
<br />
<label for="passwordinput">密码:</label>
<input type="password" id="passwordinput" name="pwd" size="12" />
<br />
<label for="passwordinput">验证:</label>
<input type="text" id="passwordinput" name="ad" size="4" />
<br />
<input name="Submit1" type="submit" id="Submit1" value="提交" />
<input type="reset" name="Submit2" value="重置" />
</form>
处理页面:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ include file="conn.jsp" %>
<%
request.setCharacterEncoding("gb2312");
String sqx=request.getParameter("qx");
int qx =Integer.parseInt(sqx);
String uid=request.getParameter("uid");
String pwd= request.getParameter("pwd");
String sql=null;
switch(qx){
case 1:sql="select * from admin where admin='"+uid+"' and pwd='"+pwd+"'";break;
case 2:sql="select * from department where d_admin='"+uid+"' and d_pwd='"+pwd+"'";break;
case 3:sql="select * from student where s_name='"+uid+"' and s_pwd='"+pwd+"'";break;
}
rs=stmt.executeQuery(sql);
boolean flag=false;
if(rs.next()){flag=true;}
if(flag==true)
{
session.setAttribute("uid",uid);
session.setAttribute("pwd",pwd);
session.setAttribute("type",sqx);
session.setAttribute("sflag","qgzx");
switch(qx){
case 1:response.sendRedirect("admin.jsp");break;
case 2:response.sendRedirect("d_manage.jsp");break;
case 3:response.sendRedirect("s_manage.jsp");break;
}
}
else{
session.setAttribute("uid",null);
session.setAttribute("pwd",null);
session.setAttribute("type",null);
%><jsp:forward page="error.jsp"/><%
}
}
catch(SQLException e2){out.println(e2);}
//rs.close();
//conn.close();
%>