www.pudn.com > bookshop.zip > LoginServlet.java, change:2013-07-08,size:1124b


package com.tarena.web; 
 
import java.io.IOException; 
import java.io.PrintWriter; 
import java.sql.Connection; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 
 
import javax.servlet.ServletException; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
 
import com.tarena.bean.User; 
import com.tarena.dao.UserDao; 
import com.tarena.util.DB; 
 
public class LoginServlet extends HttpServlet { 
 
	public void service(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException { 
		 
		request.setCharacterEncoding("utf-8"); 
		response.setContentType("text/html;charset=utf-8"); 
		String email=request.getParameter("email"); 
    	String password=request.getParameter("password"); 
    	User user = new User(); 
    	UserDao dao=new UserDao(); 
    	user=dao.checkEmailAndPwd(email,password); 
 
		if(user==null){ 
			response.sendRedirect("login.jsp"); 
		}else{ 
			request.getSession().setAttribute("user", user); 
			response.sendRedirect("BookListServlet"); 
		} 
    } 
}