Advertisement
Guest User

Untitled

a guest
Jun 21st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 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 DesenvolvedorJava
  18. */
  19. @WebServlet(urlPatterns = {"/CadastrarClienteServlet"})
  20. public class CadastrarClienteServlet 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. try (PrintWriter out = response.getWriter()) {
  35.  
  36. String nomeCliente = request.getParameter("nm");
  37.  
  38.  
  39. String url = "jdbc:mysql://localhost/bdccliente";
  40. String usuario = "root";
  41. String senha = "root";
  42. String sql = "INSERT INTO cliente (nome) VALUES (?)";
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. out.println("O nome digitado foi: " + nomeCliente);
  58.  
  59. }
  60. }
  61.  
  62. // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  63. /**
  64. * Handles the HTTP <code>GET</code> method.
  65. *
  66. * @param request servlet request
  67. * @param response servlet response
  68. * @throws ServletException if a servlet-specific error occurs
  69. * @throws IOException if an I/O error occurs
  70. */
  71. @Override
  72. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  73. throws ServletException, IOException {
  74. processRequest(request, response);
  75. }
  76.  
  77. /**
  78. * Handles the HTTP <code>POST</code> method.
  79. *
  80. * @param request servlet request
  81. * @param response servlet response
  82. * @throws ServletException if a servlet-specific error occurs
  83. * @throws IOException if an I/O error occurs
  84. */
  85. @Override
  86. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  87. throws ServletException, IOException {
  88. processRequest(request, response);
  89. }
  90.  
  91. /**
  92. * Returns a short description of the servlet.
  93. *
  94. * @return a String containing servlet description
  95. */
  96. @Override
  97. public String getServletInfo() {
  98. return "Short description";
  99. }// </editor-fold>
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement