Guest User

Untitled

a guest
Jan 28th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.92 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. public class NewClass {
  8.     private String name1,pawd;
  9. public NewClass(String name1,String password)
  10. {
  11.     this.name1=name1;
  12.    pawd=password;
  13. }
  14.     public String getName1() {
  15.         return name1;
  16.     }
  17.  
  18.     public void setName1(String name1) {
  19.         this.name1 = name1;
  20.     }
  21.  
  22.     public String getPawd() {
  23.         return pawd;
  24.     }
  25.  
  26.     public void setPawd(String pawd) {
  27.         this.pawd = pawd;
  28.     }
  29.  
  30. }
  31. --------------------------------------------------------------------------------------------------------
  32.  
  33. /*
  34.  * To change this license header, choose License Headers in Project Properties.
  35.  * To change this template file, choose Tools | Templates
  36.  * and open the template in the editor.
  37.  */
  38.  
  39. import java.io.IOException;
  40. import java.io.PrintWriter;
  41. import javax.servlet.RequestDispatcher;
  42. import javax.servlet.ServletException;
  43. import javax.servlet.annotation.WebServlet;
  44. import javax.servlet.http.HttpServlet;
  45. import javax.servlet.http.HttpServletRequest;
  46. import javax.servlet.http.HttpServletResponse;
  47. import javax.xml.registry.infomodel.User;
  48.  
  49. /**
  50.  *
  51.  * @author MRuser
  52.  */
  53. @WebServlet(urlPatterns = {"/NewServlet"})
  54. public class NewServlet extends HttpServlet {
  55.  
  56.     /**
  57.      * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
  58.      * methods.
  59.      *
  60.      * @param request servlet request
  61.      * @param response servlet response
  62.      * @throws ServletException if a servlet-specific error occurs
  63.      * @throws IOException if an I/O error occurs
  64.      */
  65.     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  66.             throws ServletException, IOException {
  67.         response.setContentType("text/html;charset=UTF-8");
  68.         try (PrintWriter out = response.getWriter()) {
  69.             /* TODO output your page here. You may use following sample code. */
  70.             out.println("<!DOCTYPE html>");
  71.             out.println("<html>");
  72.             out.println("<head>");
  73.             out.println("<title>Servlet NewServlet</title>");            
  74.             out.println("</head>");
  75.             out.println("<body>");
  76.             out.println("<h1>Servlet NewServlet at " + request.getContextPath() + "</h1>");
  77.             out.println("</body>");
  78.             out.println("</html>");
  79.             String name=request.getParameter("uname");
  80.           String pwd=request.getParameter("pass");
  81.          
  82.           NewClass u=new NewClass(name,pwd);
  83.                 RequestDispatcher rd=request.getRequestDispatcher("success.jsp");
  84.                  rd.forward(request,response);
  85.         }
  86.     }
  87.  
  88.     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  89.     /**
  90.      * Handles the HTTP <code>GET</code> method.
  91.      *
  92.      * @param request servlet request
  93.      * @param response servlet response
  94.      * @throws ServletException if a servlet-specific error occurs
  95.      * @throws IOException if an I/O error occurs
  96.      */
  97.     @Override
  98.     protected void doGet(HttpServletRequest request, HttpServletResponse response)
  99.             throws ServletException, IOException {
  100.         processRequest(request, response);
  101.     }
  102.  
  103.     /**
  104.      * Handles the HTTP <code>POST</code> method.
  105.      *
  106.      * @param request servlet request
  107.      * @param response servlet response
  108.      * @throws ServletException if a servlet-specific error occurs
  109.      * @throws IOException if an I/O error occurs
  110.      */
  111.     @Override
  112.     protected void doPost(HttpServletRequest request, HttpServletResponse response)
  113.             throws ServletException, IOException {
  114.         processRequest(request, response);
  115.     }
  116.  
  117.     /**
  118.      * Returns a short description of the servlet.
  119.      *
  120.      * @return a String containing servlet description
  121.      */
  122.     @Override
  123.     public String getServletInfo() {
  124.         return "Short description";
  125.     }// </editor-fold>
  126.  
  127. }
  128. -----------------------------------------------------------------------------------------------------------
  129. <!DOCTYPE html>
  130. <!--
  131. To change this license header, choose License Headers in Project Properties.
  132. To change this template file, choose Tools | Templates
  133. and open the template in the editor.
  134. -->
  135. <html>
  136.     <head>
  137.         <title>TODO supply a title</title>
  138.         <meta charset="UTF-8">
  139.         <meta name="viewport" content="width=device-width, initial-scale=1.0">
  140.     </head>
  141.     <body>
  142.        
  143.         <form action="NewServlet" method="get">
  144.             <p2>Username:</p2>
  145.             <input type="text" name="uname">
  146.             <p3>Password:</p3>
  147.             <input type="password" name="pass"/>
  148.             <input type="submit" value="login"/>
  149.             <input type="reset" value="cancel"/>
  150.         </form>
  151.     </body>
  152. </html>
Add Comment
Please, Sign In to add comment