Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 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 Servlets;
  7.  
  8. import java.io.IOException;
  9. import java.io.PrintWriter;
  10. import javax.servlet.ServletException;
  11. import javax.servlet.annotation.WebServlet;
  12. import javax.servlet.http.HttpServlet;
  13. import javax.servlet.http.HttpServletRequest;
  14. import javax.servlet.http.HttpServletResponse;
  15.  
  16. /**
  17. *
  18. * @author dstudent
  19. */
  20. @WebServlet(name = "WelcomeServlet", urlPatterns = {"/welcome"})
  21. public class WelcomeServlet extends HttpServlet {
  22.  
  23. /**
  24. * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
  25. * methods.
  26. *
  27. * @param request servlet request
  28. * @param response servlet response
  29. * @throws ServletException if a servlet-specific error occurs
  30. * @throws IOException if an I/O error occurs
  31. */
  32. protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  33. throws ServletException, IOException {
  34. System.out.println("In WelcomeServlet");
  35.  
  36. request.getRequestDispatcher("/login.html").forward(request, response);
  37.  
  38.  
  39. System.out.println("Out WelcomeServlet");
  40.  
  41. }
  42.  
  43. // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  44. /**
  45. * Handles the HTTP <code>GET</code> method.
  46. *
  47. * @param request servlet request
  48. * @param response servlet response
  49. * @throws ServletException if a servlet-specific error occurs
  50. * @throws IOException if an I/O error occurs
  51. */
  52. @Override
  53. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  54. throws ServletException, IOException {
  55. processRequest(request, response);
  56. }
  57.  
  58. /**
  59. * Handles the HTTP <code>POST</code> method.
  60. *
  61. * @param request servlet request
  62. * @param response servlet response
  63. * @throws ServletException if a servlet-specific error occurs
  64. * @throws IOException if an I/O error occurs
  65. */
  66. @Override
  67. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  68. throws ServletException, IOException {
  69. processRequest(request, response);
  70. }
  71.  
  72. /**
  73. * Returns a short description of the servlet.
  74. *
  75. * @return a String containing servlet description
  76. */
  77. @Override
  78. public String getServletInfo() {
  79. return "Short description";
  80. }// </editor-fold>
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement