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 3.06 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. Courses
  13. Long id
  14. String courseName
  15. String description
  16. List<String> studentNames
  17. Map<String, Long> studentNamesElligibleToRegister
  18.  
  19. public class LoginControllerServlet extends HttpServlet{
  20.  
  21. static int loginAttempt;
  22. StudentDAO studentDAO;
  23. static List<Students> students;
  24. ByteArrayOutputStream stream = new ByteArrayOutputStream();
  25. PrintWriter printWriter = new PrintWriter(stream);
  26.  
  27. public void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
  28. response.setContentType("text/html;charset=UTF-8");
  29. HttpSession session = request.getSession(true);
  30. ServletContext servletContext = getServletContext();
  31. ServletConfig servletConfig = getServletConfig();
  32.  
  33. students = studentDAO.getStudents();
  34.  
  35. Enumeration e = servletConfig.getInitParameterNames();
  36. if(request.getParameter("formType").equals("login")){
  37. loginAttempt++;
  38. if(loginAttempt > 3){
  39. printWriter.write(<html>);
  40. printWriter.write(<head>);
  41. printWriter.write(<Login Error>);
  42. printWriter.write(<body>);
  43. printWriter.write(<h1>Student is locked out of classes and cannot register for classes</h1>);
  44. printWriter.write(</body>);
  45. printWriter.write(</html>);
  46. session.setAttribute("loginOutput", stream.toString();
  47. }
  48. RequestDispatcher dispatcher = servletContext.getRequestDispatcher("/JSPLoginError.jsp");
  49. dispatcher.forward(request, response);
  50. } else if(request.getParameter("formType").equals("welcome")){
  51. if(loginAttempt > 3){
  52. printWriter.write(<html>);
  53. printWriter.write(<head>);
  54. printWriter.write(<Login Error>);
  55. printWriter.write(<body>);
  56. printWriter.write(<h1>Student is locked out of classes and cannot register for classes</h1>);
  57. printWriter.write(</body>);
  58. printWriter.write(</html>);
  59. session.setAttribute("loginOutput", stream.toString());
  60. } else {
  61.  
  62. students.forEach(x -> {
  63. if(x.userName == session.getAttribute("username") && x.password == session.getAttribute("password")){
  64. printWriter.write(<html>);
  65. printWriter.write(<head>);
  66. printWriter.write(<Login Success>);
  67. printWriter.write(<body>);
  68. printWriter.write(<h1>Student logged in successfully</h1>);
  69. printWriter.write(</body>);
  70. printWriter.write(</html>);
  71. session.setAttribute("loginOutput", stream.toString());
  72. }
  73. }
  74. }
  75. }
  76.  
  77. public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
  78. processRequest(request,response);
  79.  
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement