package Servlet; import java.io.IOException; import java.io.PrintWriter; import java.sql.SQLException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.swing.JOptionPane; import Bean.login; import Dao.loginDao; public class loginServlet extends HttpServlet { /** * */ private static final long serialVersionUID = 1L; /** * 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 init() throws ServletException { // Put your code here } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { return; } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String user = request.getParameter("user"); String password = request.getParameter("password"); System.out.println(user); response.setContentType("text/html"); PrintWriter out = response.getWriter(); try{ //login lg = new Bean.login(); System.out.println("ls2"); login lg = new loginDao().login(user); System.out.println(lg); String lgu = lg.getUser(); String lgp = lg.getPassword(); System.out.println(lgu); System.out.println(lgp); if(lgu != null ){ System.out.println("ls3"); if(lgp.equals(password)){ out.print(user); out.print(password); request.getRequestDispatcher("/index.jsp").forward(request,response); }else{ request.getRequestDispatcher("/login.jsp").forward(request, response); } }else{ System.out.println("ls4"); out.print("ok"); JOptionPane.showMessageDialog(null, "用户名不存在!"); request.getRequestDispatcher("/login.jsp").forward(request, response); } }catch(SQLException e){ e.printStackTrace(); } } /** * Initialization of the servlet. <br> * @throws IOException * * @throws ServletException if an error occurs */ /*(public static void main(String[] args) { loginServlet lse = new loginServlet(); try { lse.doPost(null, null); } catch (ServletException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("2"); } */ }
产品经理不是经理
相关分类