sergAccount

Untitled

Apr 11th, 2021
450
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 com.mycompany.service;
  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 Admin
  19.  */
  20. @WebServlet(name = "ProcessFormServlet", urlPatterns = {"/ProcessFormServlet"})
  21. public class ProcessFormServlet 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.         //
  35.         String userName = request.getParameter("uname");
  36.         String password = request.getParameter("psw");
  37.        
  38.         response.setContentType("text/html;charset=UTF-8");
  39.         try (PrintWriter out = response.getWriter()) {
  40.             /* TODO output your page here. You may use following sample code. */
  41.             out.println("<!DOCTYPE html>");
  42.             out.println("<html>");
  43.             out.println("<head>");
  44.             out.println("<title>Servlet ProcessFormServlet</title>");            
  45.             out.println("</head>");
  46.             out.println("<body>");
  47.             out.println("<h1>Servlet ProcessFormServlet at " + request.getContextPath() + "</h1>");
  48.             out.println("<div>UserName: " + userName + "</div>");
  49.             out.println("<div>Password: " + password + "</div>");
  50.             out.println("</body>");
  51.             out.println("</html>");
  52.         }
  53.     }
  54.  
  55.     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  56.     /**
  57.      * Handles the HTTP <code>GET</code> method.
  58.      *
  59.      * @param request servlet request
  60.      * @param response servlet response
  61.      * @throws ServletException if a servlet-specific error occurs
  62.      * @throws IOException if an I/O error occurs
  63.      */
  64.     @Override
  65.     protected void doGet(HttpServletRequest request, HttpServletResponse response)
  66.             throws ServletException, IOException {
  67.         processRequest(request, response);
  68.     }
  69.  
  70.     /**
  71.      * Handles the HTTP <code>POST</code> method.
  72.      *
  73.      * @param request servlet request
  74.      * @param response servlet response
  75.      * @throws ServletException if a servlet-specific error occurs
  76.      * @throws IOException if an I/O error occurs
  77.      */
  78.     @Override
  79.     protected void doPost(HttpServletRequest request, HttpServletResponse response)
  80.             throws ServletException, IOException {
  81.         processRequest(request, response);
  82.     }
  83.  
  84.     /**
  85.      * Returns a short description of the servlet.
  86.      *
  87.      * @return a String containing servlet description
  88.      */
  89.     @Override
  90.     public String getServletInfo() {
  91.         return "Short description";
  92.     }// </editor-fold>
  93.  
  94. }
  95.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×