日期:2014-05-17 浏览次数:20698 次
package com.bean;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
import com.util.*;
public class LoginBean {
Connection conn = null;
Statement st = null;
ResultSet rs = null;
ArrayList al = new ArrayList();
public int login(String name,String pwd){
int temp = 0;
conn = DBConn.getConn();
try {
st = conn.createStatement();
rs = st.executeQuery("select * from login where username='"+name+"'");
if(rs.next()){
String username = rs.getString("username");
String userpwd = rs.getString("mima");
String quanxian = rs.getString("quanxian");
if(pwd.equals(userpwd)){
temp = 1;
al.add(username);
al.add(userpwd);
al.add(quanxian);
}else{
temp = 2;
}
}else{
temp = 3;
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
DBConn.close(conn,st,rs);
}
return temp;
}
public ArrayList getArrayLst(){
return al;
}
}
package com.servlet;
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.bean.LoginBean;
public class LoginServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public LoginServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String name = request.getParameter("username");
String pwd = request.getParameter("userpwd");
String admin = request.getParameter("admin");
String xuesheng = request.getParameter("xuesheng");
String laoshi = request.getParameter("laoshi");
String str = "";
LoginBean lb = new LoginBean();
int flag = lb.login(name,pwd);
if(flag == 2 || flag == 3){