Advertisement
Guest User

Untitled

a guest
May 16th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. package edu.course.registration;
  2.  
  3. /*
  4. Tables/Objects
  5. Student
  6. Long id
  7. String username
  8. String password
  9. Boolean isRegistrationElligible
  10. Boolean isAccountLocked
  11.  
  12. public class LoginControllerServlet extends HttpServlet{
  13.  
  14. static int loginAttempt;
  15. StudentDAO studentDAO;
  16. static List<Students> students;
  17. ByteArrayOutputStream stream = new ByteArrayOutputStream();
  18. PrintWriter printWriter = new PrintWriter(stream);
  19.  
  20. public void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
  21. response.setContentType("text/html;charset=UTF-8");
  22. HttpSession session = request.getSession(true);
  23. ServletContext servletContext = getServletContext();
  24. ServletConfig servletConfig = getServletConfig();
  25.  
  26. students = studentDAO.getStudents();
  27.  
  28. Enumeration e = servletConfig.getInitParameterNames();
  29. if(request.getParameter("formType").equals("login")){
  30. loginAttempt++;
  31. if(loginAttempt > 3){
  32. printWriter.write(<html>);
  33. printWriter.write(<head>);
  34. printWriter.write(<Login Error>);
  35. printWriter.write(<body>);
  36. printWriter.write(<h1>Student is locked out of classes and cannot register for classes</h1>);
  37. printWriter.write(</body>);
  38. printWriter.write(</html>);
  39. session.setAttribute("loginOutput", stream.toString();
  40. }
  41. RequestDispatcher dispatcher = servletContext.getRequestDispatcher("/JSPLoginError.jsp");
  42. dispatcher.forward(request, response);
  43. } else if(request.getParameter("formType").equals("welcome")){
  44. if(loginAttempt > 3){
  45. printWriter.write(<html>);
  46. printWriter.write(<head>);
  47. printWriter.write(<Login Error>);
  48. printWriter.write(<body>);
  49. printWriter.write(<h1>Student is locked out of classes and cannot register for classes</h1>);
  50. printWriter.write(</body>);
  51. printWriter.write(</html>);
  52. session.setAttribute("loginOutput", stream.toString());
  53. } else {
  54.  
  55. students.forEach(x -> {
  56. if(x.userName == session.getAttribute("username") && x.password == session.getAttribute("password")){
  57. printWriter.write(<html>);
  58. printWriter.write(<head>);
  59. printWriter.write(<Login Success>);
  60. printWriter.write(<body>);
  61. printWriter.write(<h1>Student logged in successfully</h1>);
  62. printWriter.write(</body>);
  63. printWriter.write(</html>);
  64. session.setAttribute("loginOutput", stream.toString());
  65. }
  66. }
  67. }
  68. }
  69.  
  70. public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
  71. processRequest(request,response);
  72.  
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement