Advertisement
keymasterviriya1150

Untitled

Aug 21st, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 3.85 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.  
  7. import java.io.IOException;
  8. import java.io.PrintWriter;
  9. import javax.servlet.ServletException;
  10. import javax.servlet.annotation.WebServlet;
  11. import javax.servlet.http.HttpServlet;
  12. import javax.servlet.http.HttpServletRequest;
  13. import javax.servlet.http.HttpServletResponse;
  14.  
  15. /**
  16.  *
  17.  * @author STD
  18.  */
  19. @WebServlet(urlPatterns = {"/NewServlet"})
  20. public class NewServlet 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.        
  35.     }
  36.    
  37.     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  38.     /**
  39.      * Handles the HTTP <code>GET</code> method.
  40.      *
  41.      * @param request servlet request
  42.      * @param response servlet response
  43.      * @throws ServletException if a servlet-specific error occurs
  44.      * @throws IOException if an I/O error occurs
  45.      */
  46.     @Override
  47.     protected void doGet(HttpServletRequest request, HttpServletResponse response)
  48.             throws ServletException, IOException {
  49.         try (PrintWriter out = response.getWriter()) {
  50.             /* TODO output your page here. You may use following sample code. */
  51.         out.print("<html>\n" +
  52. "    <head>\n" +
  53. "        <title>TODO supply a title</title>\n" +
  54. "        <meta charset=\"UTF-8\">\n" +
  55. "        <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" +
  56. "    </head>\n" +
  57. "    <body>\n" +
  58. "        <form action=\"\" method=\"get\">\n" +
  59. "            <h1>Login GET</h1>\n" +
  60. "            <input type=\"text\" name=\"username\" value=\"\" />\n" +
  61. "            <input type=\"text\" name=\"pass\" value=\"\" />\n" +
  62. "            <input type=\"submit\" value=\"LoginGET\" name=\"LoginGET\" />\n" +
  63. "        </form>\n" +
  64. "        \n" +
  65. "        <form action=\"\" method=\"post\">\n" +
  66. "             <h1>Login POST</h1>                                                                                                                   \n" +
  67. "            <input type=\"text\" name=\"username\" value=\"\" />\n" +
  68. "            <input type=\"text\" name=\"pass\" value=\"\" />\n" +
  69. "            <input type=\"submit\" value=\"LoginPOST\" name=\"LoginPOST\" />\n" +
  70. "        </form>\n" +
  71. "        \n" +
  72. "    </body>\n" +
  73. "</html>\n" +
  74. "");
  75.         }  
  76.        
  77.     }
  78.  
  79.     /**
  80.      * Handles the HTTP <code>POST</code> method.
  81.      *
  82.      * @param request servlet request
  83.      * @param response servlet response
  84.      * @throws ServletException if a servlet-specific error occurs
  85.      * @throws IOException if an I/O error occurs
  86.      */
  87.     @Override
  88.     protected void doPost(HttpServletRequest request, HttpServletResponse response)
  89.             throws ServletException, IOException {
  90.              try (PrintWriter out = response.getWriter()) {
  91.                  out.print("<h1>help</h1>"+ request.getContextPath()
  92.                  +" "+request.getProtocol()+" "+request.getServerPort());
  93.              
  94.                  
  95.              }
  96.        
  97.     }
  98.  
  99.     /**
  100.      * Returns a short description of the servlet.
  101.      *
  102.      * @return a String containing servlet description
  103.      */
  104.     @Override
  105.     public String getServletInfo() {
  106.         return "Short description";
  107.     }// </editor-fold>
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement