Guest User

Untitled

a guest
Feb 20th, 2019
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. HTML CODE FOE LOGIN PAGE
  2.  
  3.  
  4. <!--
  5. To change this template, choose Tools | Templates
  6. and open the template in the editor.
  7. -->
  8. <!DOCTYPE html>
  9. <html>
  10. <head>
  11. <title></title>
  12. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  13. </head>
  14. <body>
  15. <form name="loginform" action="loginservlet" method="post">
  16. <h1 align="center">userlogin</h1>
  17. username:<input type="text" name="uname" value="" size="25" />
  18. password:<input type="password" name="pwd" value="" size="25" />
  19. <input type="submit" value="login" name="login" />
  20. </form>
  21. </body>
  22. </html>
  23. -----------------------------------------------------------------------------------------------------------
  24. SERVLET CODE FOR LOGIN
  25.  
  26. /*
  27. * To change this template, choose Tools | Templates
  28. * and open the template in the editor.
  29. */
  30. package ourpack;
  31.  
  32. import java.io.IOException;
  33. import java.io.PrintWriter;
  34. import javax.servlet.ServletException;
  35. import javax.servlet.http.HttpServlet;
  36. import javax.servlet.http.HttpServletRequest;
  37. import javax.servlet.http.HttpServletResponse;
  38.  
  39. /**
  40. *
  41. * @author student
  42. */
  43. public class loginservlet extends HttpServlet {
  44.  
  45. /**
  46. * Processes requests for both HTTP
  47. * <code>GET</code> and
  48. * <code>POST</code> methods.
  49. *
  50. * @param request servlet request
  51. * @param response servlet response
  52. * @throws ServletException if a servlet-specific error occurs
  53. * @throws IOException if an I/O error occurs
  54. */
  55. protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  56. throws ServletException, IOException {
  57. response.setContentType("text/html;charset=UTF-8");
  58. PrintWriter out = response.getWriter();
  59. try {
  60. String s1 = request.getParameter("uname");
  61. String s2 = request.getParameter("pwd");
  62. out.println("your username is:"+s1+"<br/>password is"+s2);
  63. System.out.println("user is"+s1+"password is"+s2);
  64.  
  65. } finally {
  66. out.close();
  67. }
  68. }
  69.  
  70. // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  71. /**
  72. * Handles the HTTP
  73. * <code>GET</code> method.
  74. *
  75. * @param request servlet request
  76. * @param response servlet response
  77. * @throws ServletException if a servlet-specific error occurs
  78. * @throws IOException if an I/O error occurs
  79. */
  80. @Override
  81. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  82. throws ServletException, IOException {
  83. processRequest(request, response);
  84. }
  85.  
  86. /**
  87. * Handles the HTTP
  88. * <code>POST</code> method.
  89. *
  90. * @param request servlet request
  91. * @param response servlet response
  92. * @throws ServletException if a servlet-specific error occurs
  93. * @throws IOException if an I/O error occurs
  94. */
  95. @Override
  96. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  97. throws ServletException, IOException {
  98. processRequest(request, response);
  99. }
  100.  
  101. /**
  102. * Returns a short description of the servlet.
  103. *
  104. * @return a String containing servlet description
  105. */
  106. @Override
  107. public String getServletInfo() {
  108. return "Short description:it displays as it is";
  109. }// </editor-fold>
  110. }
Add Comment
Please, Sign In to add comment