SrJefers_Loading

servlet

Sep 6th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 KB | None | 0 0
  1. -->
  2. <html>
  3. <head>
  4. <title>Ejemplo</title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
  8.  
  9. </head>
  10. <body bgcolor="#0B5774">
  11. <h1 style="color:white;" align="center">Ingreso de Datos</h1>
  12. <form id="form1" name="form1" method="post" action="index_servlet">
  13. <table border="0" align="center">
  14. <tr>
  15. <td width="70" height="30" style="color:white;">Nombre:</td>
  16. <td width="100" height="30"><input name="user" type="text" id="usuario" size="20"></td>
  17. </tr>
  18. <tr>
  19. <td width="70" height="30" style="color:white;">Correo:</td>
  20. <td width="100" height="30"><input name="email" type="text" id="correo" size="20"></td>
  21. </tr>
  22. <tr>
  23. <td width="70" height="30" style="color:white;">Direccion:</td>
  24. <td width="100" height="30"><input name="adress" type="text" id="direccion" size="20"></td>
  25. </tr>
  26. <tr>
  27. <td width="70" height="30" style="color:white;"><input type="reset" name="limpiar" id="limpiar" value="Limpiar"></td>
  28. <td width="100" height="30"><input type="submit" name="enviar" id="enviar" value="Enviar"></td>
  29. </tr>
  30.  
  31. </table>
  32.  
  33.  
  34. </body>
  35. </html>
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. import java.io.IOException;
  49. import java.io.PrintWriter;
  50. import javax.servlet.ServletException;
  51. import javax.servlet.annotation.WebServlet;
  52. import javax.servlet.http.HttpServlet;
  53. import javax.servlet.http.HttpServletRequest;
  54. import javax.servlet.http.HttpServletResponse;
  55.  
  56. /**
  57. *
  58. * @author alumno
  59. */
  60. @WebServlet(urlPatterns = {"/index_servlet"})
  61. public class index_servlet extends HttpServlet {
  62.  
  63. /**
  64. * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
  65. * methods.
  66. *
  67. * @param request servlet request
  68. * @param response servlet response
  69. * @throws ServletException if a servlet-specific error occurs
  70. * @throws IOException if an I/O error occurs
  71. */
  72. protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  73. throws ServletException, IOException {
  74. response.setContentType("text/html;charset=UTF-8");
  75. try (PrintWriter out = response.getWriter()) {
  76. /* TODO output your page here. You may use following sample code. */
  77. String nom= request.getParameter("user");
  78. String cor= request.getParameter("email");
  79. String dir= request.getParameter("adress");
  80.  
  81. out.println("<!DOCTYPE html>");
  82. out.println("<html>");
  83. out.println("<head>");
  84. out.println("<title>Servlet index_servlet</title>");
  85. out.println("</head>");
  86. out.println("<body>");
  87. out.println("<h1>Servlet index_servlet at " + request.getContextPath() + "</h1>");
  88.  
  89. out.println("<h2>Nombre ingresado: "+nom+"</h2>");
  90. out.println("<h2>Correo ingresado: "+cor+"</h2>");
  91. out.println("<h2>Direccion ingresado: "+dir+"</h2>");
  92.  
  93. out.println("</body>");
  94. out.println("</html>");
  95. }
  96. }
  97.  
  98. // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  99. /**
  100. * Handles the HTTP <code>GET</code> method.
  101. *
  102. * @param request servlet request
  103. * @param response servlet response
  104. * @throws ServletException if a servlet-specific error occurs
  105. * @throws IOException if an I/O error occurs
  106. */
  107. @Override
  108. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  109. throws ServletException, IOException {
  110. processRequest(request, response);
  111. }
  112.  
  113. /**
  114. * Handles the HTTP <code>POST</code> method.
  115. *
  116. * @param request servlet request
  117. * @param response servlet response
  118. * @throws ServletException if a servlet-specific error occurs
  119. * @throws IOException if an I/O error occurs
  120. */
  121. @Override
  122. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  123. throws ServletException, IOException {
  124. processRequest(request, response);
  125. }
  126.  
  127. /**
  128. * Returns a short description of the servlet.
  129. *
  130. * @return a String containing servlet description
  131. */
  132. @Override
  133. public String getServletInfo() {
  134. return "Short description";
  135. }// </editor-fold>
  136.  
  137. }
Advertisement
Add Comment
Please, Sign In to add comment