Guest User

Untitled

a guest
May 14th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. </head>
  5. <body>
  6. <form action="./registration" method="get">
  7. Name:<input type="text" name="name"><br/>
  8. Father Name: <input type="text" name="fname"><br/>
  9. Mother Name: <input type="text" name="mname"><br/>
  10. <input type="hidden" name="formd" value="1"/>
  11. <input type="submit" value="Next>>>">
  12. </form>
  13. </body>
  14. </html>
  15.  
  16. form2.html
  17. <!DOCTYPE html>
  18. <html>
  19. <head>
  20. </head>
  21. <body>
  22. <form action="./registration">
  23. Contact:<input type="text" name= "contact"><br/>
  24. Email: <input type= "text" name= "email"><br/>
  25. Address: <input type ="text" name= "address"><br/>
  26. <input type="hidden" name= "formd" value="2"/>
  27. <input type= "submit" value="Next>>>">
  28. </form>
  29. </body>
  30. </html>
  31.  
  32. form3.html
  33. <!DOCTYPE html>
  34. <html>
  35. <head>
  36. </head>
  37. <body>
  38. <form action="./registration">
  39. Qualification:<input type="text" name= "qualification"><br/>
  40. Percentage: <input type ="text" name= "percentage"><br/>
  41. <input type="hidden" name= "formd" value="3"/>
  42. <input type= "submit" value="Submit!">
  43. </form>
  44. </body>
  45. </html>
  46.  
  47. package controller;
  48.  
  49. import java.io.IOException;
  50. import java.io.PrintWriter;
  51. import java.sql.Connection;
  52. import java.sql.DriverManager;
  53. import java.sql.PreparedStatement;
  54. import java.sql.SQLException;
  55.  
  56. import javax.servlet.ServletException;
  57. import javax.servlet.http.HttpServlet;
  58. import javax.servlet.http.HttpServletRequest;
  59. import javax.servlet.http.HttpServletResponse;
  60. import javax.servlet.http.HttpSession;
  61.  
  62. public class AadharRegistration extends HttpServlet {
  63. private static final long serialVersionUID = 1L;
  64.  
  65. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  66. throws ServletException, IOException {
  67. PrintWriter out = response.getWriter();
  68.  
  69. HttpSession httpsession = request.getSession();
  70. String fno = request.getParameter("formd");
  71.  
  72. if (fno.equals("1")) {
  73. String name = request.getParameter("name");
  74. String fname = request.getParameter("fname");
  75. String mname = request.getParameter("mname");
  76.  
  77. httpsession.setAttribute("name", name);
  78. httpsession.setAttribute("fname", fname);
  79. httpsession.setAttribute("mname", mname);
  80.  
  81. response.sendRedirect("./form2.html");
  82. }
  83.  
  84. if (fno.equals("2")) {
  85. String contact = request.getParameter("contact");
  86. String email = request.getParameter("email");
  87. String address = request.getParameter("address");
  88.  
  89. httpsession.setAttribute("contact", contact);
  90. httpsession.setAttribute("email", email);
  91. httpsession.setAttribute("address", address);
  92.  
  93. response.sendRedirect("./form3.html");
  94.  
  95. }
  96.  
  97. if (fno.equals("3")) {
  98.  
  99. String qualification = request.getParameter("qualification");
  100. String percentage = request.getParameter("percentage");
  101.  
  102. String name = (String) httpsession.getAttribute("name");
  103. String fname = (String) httpsession.getAttribute("fname");
  104. String mname = (String) httpsession.getAttribute("mname");
  105.  
  106. String contact = (String) httpsession.getAttribute("contact");
  107. String email = (String) httpsession.getAttribute("email");
  108. String address = (String) httpsession.getAttribute("address");
  109.  
  110. try {
  111. Class.forName("oracle.jdbc.OracleDriver");
  112. Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:p1aor01", "system",
  113. "sysdba");
  114.  
  115. PreparedStatement ps = conn.prepareStatement("insert into aadhar values (?,?,?,?,?,?,?,?)");
  116. ps.setString(1, name);
  117. ps.setString(2, fname);
  118. ps.setString(3, mname);
  119. ps.setString(4, contact);
  120. ps.setString(5, email);
  121. ps.setString(6, address);
  122. ps.setString(7, qualification);
  123. ps.setString(8, percentage);
  124.  
  125. int res = ps.executeUpdate();
  126.  
  127. if (res != 0) {
  128. out.println("<font color='green'><h1>Registered Successfully!</h1>");
  129. }
  130.  
  131. } catch (SQLException e) {
  132. out.println("<font color='red'><h1>Registration exception Failed!</h1>");
  133. e.printStackTrace();
  134. } catch (ClassNotFoundException xe) {
  135. xe.printStackTrace();
  136. }
  137. }
  138. }
  139.  
  140. }
  141.  
  142. java.lang.NullPointerException
  143. controller.AadharRegistration.doGet(AadharRegistration.java:26)
  144. javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
  145. javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
  146. org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  147.  
  148.  
  149. Note The full stack trace of the root cause is available in the server logs.
  150.  
  151. From Console in eclipse:
  152. SEVERE: Servlet.service() for servlet [AadharRegistration] in context with path [/TestAadharRegistration] threw exception
  153. java.lang.NullPointerException
  154. at controller.AadharRegistration.doGet(AadharRegistration.java:26)
Add Comment
Please, Sign In to add comment