Guest User

Untitled

a guest
Mar 5th, 2017
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. package Assignment1;
  2.  
  3. /*
  4. * To change this license header, choose License Headers in Project Properties.
  5. * To change this template file, choose Tools | Templates
  6. * and open the template in the editor.
  7. */
  8.  
  9. import java.io.IOException;
  10. import java.io.PrintWriter;
  11. import java.sql.SQLException;
  12. import java.util.logging.Level;
  13. import java.util.logging.Logger;
  14. import javax.servlet.ServletException;
  15. import javax.servlet.http.HttpServlet;
  16. import javax.servlet.http.HttpServletRequest;
  17. import javax.servlet.http.HttpServletResponse;
  18. import javax.servlet.http.HttpSession;
  19. import Assignment1.DBService;
  20. /**
  21. *
  22. * @author Simran
  23. *
  24. *
  25. */
  26. public class userreg extends HttpServlet {
  27.  
  28. /**
  29. * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
  30. * methods.
  31. *
  32. * @param request servlet request
  33. * @param response servlet response
  34. * @throws ServletException if a servlet-specific error occurs
  35. * @throws IOException if an I/O error occurs
  36. * @throws java.sql.SQLException
  37. */
  38. protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  39. throws ServletException, IOException,SQLException {
  40. response.setContentType("text/html;charset=UTF-8");
  41. PrintWriter out = response.getWriter();
  42.  
  43. String user=request.getParameter("username");
  44. String pass=request.getParameter("pass");
  45. String cpass=request.getParameter("cpass");
  46. String email=request.getParameter("email");
  47. String fname=request.getParameter("fname");
  48. String lname =request.getParameter("lname");
  49. String gender =request.getParameter("gender");
  50.  
  51. String phone=request.getParameter("phone");
  52. out.print(user);
  53. HttpSession session = request.getSession(false);
  54. if(true)
  55. {
  56.  
  57.  
  58. String q="insert into registeruser values('"+fname+"','"+lname+"','"+user+"','"+pass+"','"+email+"','"+gender+"','"+phone+"')";
  59. int i=DBService.updateData(q);
  60. String msg=" ";
  61. if(i!=0){
  62. msg="Record has been inserted";
  63. out.println("<font size='6' color=blue>" + msg + "</font>");
  64. response.sendRedirect("index.html");
  65.  
  66.  
  67. }
  68. else{
  69. msg="failed to insert the data";
  70. out.println("<font size='6' color=blue>" + q + "</font>");
  71. response.sendRedirect("registration.html");}
  72.  
  73.  
  74. }
  75.  
  76.  
  77.  
  78.  
  79.  
  80. }
  81.  
  82. // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  83. /**
  84. * Handles the HTTP <code>GET</code> method.
  85. *
  86. * @param request servlet request
  87. * @param response servlet response
  88. * @throws ServletException if a servlet-specific error occurs
  89. * @throws IOException if an I/O error occurs
  90. */
  91. @Override
  92. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  93. throws ServletException, IOException {
  94. try {
  95. processRequest(request, response);
  96. } catch (SQLException ex) {
  97. Logger.getLogger(userreg.class.getName()).log(Level.SEVERE, null, ex);
  98. }
  99. }
  100.  
  101.  
  102.  
  103. @Override
  104. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  105. throws ServletException, IOException {
  106. try {
  107. processRequest(request, response);
  108. } catch (SQLException ex) {
  109. Logger.getLogger(userreg.class.getName()).log(Level.SEVERE, null, ex);
  110. }
  111. }
  112.  
  113. /**
  114. * Handles the HTTP <code>POST</code> method.
  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. }
Add Comment
Please, Sign In to add comment