/** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub try { User user = new User(); services.ServiceProxy proxy = new services.ServiceProxy(); proxy.setEndpoint("http://localhost:8080/CMPE273VideoLibrary/services/Service"); System.out.println("Login :::::::: Form Submitted"); String username = request.getParameter("username"); String password = request.getParameter("password"); // System.out.println("Username :::::::" + username); // System.out.println("Password :::::::" + password); user = proxy.signIn(username, password); if (user.getErrorMsg().equals("SUCCESS")) { if ((user.getPreference().getPreferenceId() == 1) || (user.getPreference().getPreferenceId() == 2) || (user.getPreference().getPreferenceId() == 3)) { HttpSession session = request.getSession(); session.setAttribute("user", user); response.sendRedirect("Home.jsp"); } } else { request.setAttribute("errorMsg", user.getErrorMsg()); System.out.println("error Msg in servlet:" + request.getAttribute("errorMsg")); // response.sendRedirect("SignIn.jsp"); RequestDispatcher requestDispatcher = request.getRequestDispatcher("Login.jsp"); requestDispatcher.forward(request, response); } } catch (Exception e) { e.printStackTrace(); } }
/** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub int page = 1; int recordsPerPage = 5; if (request.getParameter("page") != null) { page = Integer.parseInt(request.getParameter("page")); } services.ServiceProxy proxy = new services.ServiceProxy(); proxy.setEndpoint("http://localhost:8080/CMPE273VideoLibrary/services/Service"); /*since the prefernce id for all simple user is 1 we are passing input as 1*/ User[] user = proxy.displayUsers(1, (page - 1) * recordsPerPage, recordsPerPage); int noOfRecords = proxy.getNoOfRecords(); int noOfPages = (int) Math.ceil(noOfRecords * 1.0 / recordsPerPage); request.setAttribute("user", user); request.setAttribute("noOfPages", noOfPages); request.setAttribute("currentPage", page); RequestDispatcher view = request.getRequestDispatcher("displayUser.jsp"); view.forward(request, response); System.out.println("List of simple users size:::" + user.length); }