Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package edu.course.registration;
- /*
- Tables/Objects
- Student
- Long id
- String username
- String password
- Boolean isRegistrationElligible
- Boolean isAccountLocked
- Courses
- Long id
- String courseName
- String description
- List<String> studentNames
- Map<String, Long> studentNamesElligibleToRegister
- public class LoginControllerServlet extends HttpServlet{
- static int loginAttempt;
- StudentDAO studentDAO;
- static List<Students> students;
- ByteArrayOutputStream stream = new ByteArrayOutputStream();
- PrintWriter printWriter = new PrintWriter(stream);
- public void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
- response.setContentType("text/html;charset=UTF-8");
- HttpSession session = request.getSession(true);
- ServletContext servletContext = getServletContext();
- ServletConfig servletConfig = getServletConfig();
- students = studentDAO.getStudents();
- Enumeration e = servletConfig.getInitParameterNames();
- if(request.getParameter("formType").equals("login")){
- loginAttempt++;
- if(loginAttempt > 3){
- printWriter.write(<html>);
- printWriter.write(<head>);
- printWriter.write(<Login Error>);
- printWriter.write(<body>);
- printWriter.write(<h1>Student is locked out of classes and cannot register for classes</h1>);
- printWriter.write(</body>);
- printWriter.write(</html>);
- session.setAttribute("loginOutput", stream.toString();
- }
- RequestDispatcher dispatcher = servletContext.getRequestDispatcher("/JSPLoginError.jsp");
- dispatcher.forward(request, response);
- } else if(request.getParameter("formType").equals("welcome")){
- if(loginAttempt > 3){
- printWriter.write(<html>);
- printWriter.write(<head>);
- printWriter.write(<Login Error>);
- printWriter.write(<body>);
- printWriter.write(<h1>Student is locked out of classes and cannot register for classes</h1>);
- printWriter.write(</body>);
- printWriter.write(</html>);
- session.setAttribute("loginOutput", stream.toString());
- } else {
- students.forEach(x -> {
- if(x.userName == session.getAttribute("username") && x.password == session.getAttribute("password")){
- printWriter.write(<html>);
- printWriter.write(<head>);
- printWriter.write(<Login Success>);
- printWriter.write(<body>);
- printWriter.write(<h1>Student logged in successfully</h1>);
- printWriter.write(</body>);
- printWriter.write(</html>);
- session.setAttribute("loginOutput", stream.toString());
- }
- }
- }
- }
- public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
- processRequest(request,response);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement