Advertisement
Guest User

Untitled

a guest
Apr 6th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package Controller;
  7.  
  8. import Login.Login;
  9. import java.io.IOException;
  10. import java.io.PrintWriter;
  11. import javax.servlet.ServletException;
  12. import javax.servlet.http.HttpServlet;
  13. import javax.servlet.http.HttpServletRequest;
  14. import javax.servlet.http.HttpServletResponse;
  15.  
  16. /**
  17. *
  18. * @author ivoni
  19. */
  20. public class Logger extends HttpServlet {
  21.  
  22. /**
  23. * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
  24. * methods.
  25. *
  26. * @param request servlet request
  27. * @param response servlet response
  28. * @throws ServletException if a servlet-specific error occurs
  29. * @throws IOException if an I/O error occurs
  30. */
  31. protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  32. throws ServletException, IOException {
  33. response.setContentType("text/html;charset=UTF-8");
  34. Login login = new Login();
  35. String userName = request.getParameter("userName");
  36. String password = request.getParameter("password");
  37. if(login.log(userName, password))
  38. {
  39. request.getRequestDispatcher("welcome.jsp").forward(request, response);
  40. }
  41. else
  42. {
  43. request.getRequestDispatcher("logger.jsp").forward(request, response);
  44. }
  45.  
  46. }
  47.  
  48. // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  49. /**
  50. * Handles the HTTP <code>GET</code> method.
  51. *
  52. * @param request servlet request
  53. * @param response servlet response
  54. * @throws ServletException if a servlet-specific error occurs
  55. * @throws IOException if an I/O error occurs
  56. */
  57. @Override
  58. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  59. throws ServletException, IOException {
  60. processRequest(request, response);
  61. }
  62.  
  63. /**
  64. * Handles the HTTP <code>POST</code> method.
  65. *
  66. * @param request servlet request
  67. * @param response servlet response
  68. * @throws ServletException if a servlet-specific error occurs
  69. * @throws IOException if an I/O error occurs
  70. */
  71. @Override
  72. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  73. throws ServletException, IOException {
  74. processRequest(request, response);
  75. }
  76.  
  77. /**
  78. * Returns a short description of the servlet.
  79. *
  80. * @return a String containing servlet description
  81. */
  82. @Override
  83. public String getServletInfo() {
  84. return "Short description";
  85. }// </editor-fold>
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement