在做学生管理系统,登录界面和登录验证代码如下,login.jsp:
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030" import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>学生管理系统用户登录</title>
</head>
<body>
<table align="center" width="800" border="0" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
<tr>
<td width="100%" height="200" align="left"><img src="Picture/book.jpg" width="100%" height="200" align="left"></img>
<td width="100" height="100" align="right"><img src="Picture/adb.jpg" width="100" height="100" align="right"></img>
</td>
</tr>
</table>
<%String button1=request.getParameter("button1"); %>
<%if(button1==null) {%>
<table align="center" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" height="100" ></td>
</tr>
<tr>
<td width="100%" align="justify">
<form method="post" action="login.jsp" name="login_form">
<p align="center">用户:<input type="text" name="userName" size="20"></input></p>
<p align="center">密码:<input type="password" name="password" size="20"></input></p>
<p align="center">
<input type="radio" name="systemrole" value="student">学生
<input type="radio" name="systemrole" value="teacher" >教师
<input type="radio" name="systemrole" value="administer">管理员</p>
<p align="center"><input align="left" class="buttonface" type="submit" value="确定" name="button1">
<input class="buttonface" type="reset" value="重写" name="button2"></p>
</form>
</td>
</tr>
</table>
<%} else{
request.setCharacterEncoding("GBK");
String userName,password,systemrole;
userName=(String)request.getParameter("userName");
password=(String)request.getParameter("password");
systemrole=(String)request.getParameter("systemrole");
userName.trim();
password.trim();
systemrole.trim();
if((userName==null)||(password==null)){
response.sendRedirect("./login.jsp");
}
else{
Connection con=null;
Statement s=null;
ResultSet r=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:stud","sa","110");
s=con.createStatement();
String sqlstring=null;
if(systemrole.equals("teacher")) sqlstring=new String("select * from teacher where Tno='"+userName+"' and Tpassword='"+password+"'");
else if(systemrole.equals("administer")) sqlstring=new String("select * from administer where Ano='"+userName+"' and Apassword='"+password+"'");
else if(systemrole.equals("student"))sqlstring=new String("select * from student where Sno='"+userName+"' and Spassword='"+password+"'");