// Path: src/edu/zjut/dao/impl/AdminDaoImpl.java
// public class AdminDaoImpl implements AdminDao {
// 	
// 	private PreparedStatement pstmt = null;
// 	private ResultSet rs = null;
// 	private Connection connection = null;
// 	private DBHelp dbHelp = new DBHelp();
// 	
// 	public AdminDaoImpl() {
// 		connection = dbHelp.getConn();
// 	}
// 	
// 	/**
// 	 * 通过Email和密码获取管理对象
// 	 * @param email
// 	 * @param password
// 	 * @return
// 	 * @throws SQLException
// 	 */
// 	@Override
// 	public Admin getAdmin(String email, String password) throws SQLException {
// 		connection = dbHelp.getConn();
// 		String sql = "SELECT * FROM t_admin WHERE name = ? AND adminpwd = ?";
// 		pstmt = connection.prepareStatement(sql);
// 		pstmt.setString(1, email);
// 		pstmt.setString(2, password);
// 		rs = pstmt.executeQuery();
// 		Admin admin = new Admin();
// 		if (rs.next()) {
// 			admin.setAdminId(rs.getInt("adminId"));
// 			admin.setName(rs.getString("name"));
// 			admin.setPassword(rs.getString("password"));
// 		}
// 		dbHelp.closeConn();
// 		return admin;
// 	}
// }
// 
// Path: src/edu/zjut/model/Admin.java
// public class Admin implements Serializable {
// 
// 	private static final long serialVersionUID = 1L;
// 	
// 	private int adminId;
// 	private String name;
// 	private String salt;
// 	private String password;
// 
// 	public Admin() {
// 	}
// 
// 	public Admin(String name, String password) {
// 		setName(name);
// 		setPassword(password);
// 	}
// 
// 	public int getAdminId() {
// 		return adminId;
// 	}
// 
// 	public void setAdminId(int adminId) {
// 		this.adminId = adminId;
// 	}
// 
// 	public String getName() {
// 		return name;
// 	}
// 
// 	public void setName(String name) {
// 		this.name = name;
// 	}
// 
// 	public String getSalt() {
// 		return salt;
// 	}
// 
// 	public void setSalt(String salt) {
// 		this.salt = salt;
// 	}
// 
// 	public String getPassword() {
// 		return password;
// 	}
// 
// 	public void setPassword(String password) {
// 		this.password = password;
// 	}
// }


import java.io.IOException;
import java.sql.SQLException;
import java.util.regex.Pattern;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import edu.zjut.dao.impl.AdminDaoImpl;
import edu.zjut.model.Admin;
package edu.zjut.servlet;




@WebServlet(name = "AdminLoginServlet", urlPatterns = { "/admin/login.do" })
public class AdminLoginServlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
	private static final String USERNAME = "RG@zjut.edu.cn";
	private static final String PASSWORD = "admin201615162";

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		super.doGet(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String email = request.getParameter("email").trim().toString();
		String password = request.getParameter("password").trim().toString();
		AdminDaoImpl adminDao = new AdminDaoImpl();
		try {
			adminDao.getAdmin(email, password);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		// 判断用户名、密码是否为空
		if (!"".equals(email) && !"".equals(password)) {
			// 判断用户名、密码是否符合规则
			if(validateEmail(email)) {
				if (validatePassword(password)) {
					// 判断用户名、密码是否正确
					if (email.equals(USERNAME) && password.equals(PASSWORD)) {
// Path: src/edu/zjut/dao/impl/AdminDaoImpl.java
// public class AdminDaoImpl implements AdminDao {
// 	
// 	private PreparedStatement pstmt = null;
// 	private ResultSet rs = null;
// 	private Connection connection = null;
// 	private DBHelp dbHelp = new DBHelp();
// 	
// 	public AdminDaoImpl() {
// 		connection = dbHelp.getConn();
// 	}
// 	
// 	/**
// 	 * 通过Email和密码获取管理对象
// 	 * @param email
// 	 * @param password
// 	 * @return
// 	 * @throws SQLException
// 	 */
// 	@Override
// 	public Admin getAdmin(String email, String password) throws SQLException {
// 		connection = dbHelp.getConn();
// 		String sql = "SELECT * FROM t_admin WHERE name = ? AND adminpwd = ?";
// 		pstmt = connection.prepareStatement(sql);
// 		pstmt.setString(1, email);
// 		pstmt.setString(2, password);
// 		rs = pstmt.executeQuery();
// 		Admin admin = new Admin();
// 		if (rs.next()) {
// 			admin.setAdminId(rs.getInt("adminId"));
// 			admin.setName(rs.getString("name"));
// 			admin.setPassword(rs.getString("password"));
// 		}
// 		dbHelp.closeConn();
// 		return admin;
// 	}
// }
// 
// Path: src/edu/zjut/model/Admin.java
// public class Admin implements Serializable {
// 
// 	private static final long serialVersionUID = 1L;
// 	
// 	private int adminId;
// 	private String name;
// 	private String salt;
// 	private String password;
// 
// 	public Admin() {
// 	}
// 
// 	public Admin(String name, String password) {
// 		setName(name);
// 		setPassword(password);
// 	}
// 
// 	public int getAdminId() {
// 		return adminId;
// 	}
// 
// 	public void setAdminId(int adminId) {
// 		this.adminId = adminId;
// 	}
// 
// 	public String getName() {
// 		return name;
// 	}
// 
// 	public void setName(String name) {
// 		this.name = name;
// 	}
// 
// 	public String getSalt() {
// 		return salt;
// 	}
// 
// 	public void setSalt(String salt) {
// 		this.salt = salt;
// 	}
// 
// 	public String getPassword() {
// 		return password;
// 	}
// 
// 	public void setPassword(String password) {
// 		this.password = password;
// 	}
// }


// Path: src/edu/zjut/servlet/AdminLoginServlet.java
import java.io.IOException;
import java.sql.SQLException;
import java.util.regex.Pattern;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import edu.zjut.dao.impl.AdminDaoImpl;
import edu.zjut.model.Admin;

package edu.zjut.servlet;




@WebServlet(name = "AdminLoginServlet", urlPatterns = { "/admin/login.do" })
public class AdminLoginServlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
	private static final String USERNAME = "RG@zjut.edu.cn";
	private static final String PASSWORD = "admin201615162";

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		super.doGet(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String email = request.getParameter("email").trim().toString();
		String password = request.getParameter("password").trim().toString();
		AdminDaoImpl adminDao = new AdminDaoImpl();
		try {
			adminDao.getAdmin(email, password);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		// 判断用户名、密码是否为空
		if (!"".equals(email) && !"".equals(password)) {
			// 判断用户名、密码是否符合规则
			if(validateEmail(email)) {
				if (validatePassword(password)) {
					// 判断用户名、密码是否正确
					if (email.equals(USERNAME) && password.equals(PASSWORD)) {
						Admin admin = new Admin(email, password);