@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { try { UserBean user = new UserBean(); user.setQuery( "SELECT * FROM creditcard WHERE number='" + request.getParameter("cardnumber") + "'"); user = UserDAO.login(user); boolean coba = user.isValid(); if (user.isValid()) { response.getWriter().print(true); } else response.getWriter().print(false); } catch (Throwable theException) { System.out.println(theException); } }
/** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub { try { UserBean user = new UserBean(); ArrayList<ArrayList<String>> questions = new ArrayList<ArrayList<String>>(); // ArrayList<CartBean> cart=new ArrayList<CartBean>(); user.setUserName(request.getParameter("un")); user.setPassword(request.getParameter("pw")); user = UserDAO.login(user); if (user.isValid()) { // cart = CartDAO.items(); questions = questionsDAO.items(); System.out.println(user.getUsername()); HttpSession session = request.getSession(true); if (user.getPosition() > 0) { HashMap<String, int[]> ratingMap = new ratingDAO().update(user.getUsername()); session.setAttribute("ratingMap", ratingMap); } session.setAttribute("currentSessionUser", user); session.setAttribute("questions", questions); response.sendRedirect("index.jsp"); // logged-in page } else { String h = "Invalid Credentials"; request.setAttribute("message", h); RequestDispatcher view = getServletContext().getRequestDispatcher("/login.jsp"); view.forward(request, response); // response.sendRedirect("login.jsp"); } // error page } catch (Throwable theException) { theException.printStackTrace(); } } }