Guest User

Hi Shreya

a guest
Jul 9th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 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 java.sql.Connection;
  10. import java.sql.ResultSet;
  11. import java.sql.Statement;
  12. import javax.servlet.RequestDispatcher;
  13. import javax.servlet.ServletException;
  14. import javax.servlet.annotation.WebServlet;
  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.  
  20. /**
  21. *
  22. * @author wrtrg1
  23. */
  24. @WebServlet(urlPatterns = {"/updateUserPendingComplaintList"})
  25. public class updateUserPendingComplaintList extends HttpServlet {
  26.  
  27. //Database credentials:
  28. static final String urrrl = "jdbc:oracle:thin:@10.147.66.56:1521:XE";
  29. static final String USER = "SYSTEM";
  30. static final String PASS = "123456";
  31.  
  32. /**
  33. * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
  34. * methods.
  35. *
  36. * @param request servlet request
  37. * @param response servlet response
  38. * @throws ServletException if a servlet-specific error occurs
  39. * @throws IOException if an I/O error occurs
  40. */
  41. protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  42. throws ServletException, IOException {
  43. response.setContentType("text/html;charset=UTF-8");
  44. HttpSession session = request.getSession();
  45. RequestDispatcher rd;
  46. Connection conn = null;
  47. Statement stmt = null;
  48. ResultSet rs = null;
  49.  
  50. /*
  51.  
  52. Part 1: Making the query.
  53.  
  54. Make the base queriy that includes the default condition for pending complaints
  55.  
  56. Make use of request.getParameter to get the values of various HTML input fields from previous page form
  57.  
  58. Use an if else ladder to make use of these input fields
  59. -If the fields are null do nothig and check the next field
  60. If the field is not null, add the "AND FIELDNAME="+fieldvariableontainingvalue string to the original query
  61.  
  62. The above if else ladder should completey create your query as needed
  63.  
  64. Step @: Getting the complaints in required list/set
  65.  
  66. Run the query and that should return a result set
  67.  
  68. Go through this result set in a while loop using rs.next()
  69.  
  70. Store each of the required info in a ComplaintModel object, and on setting values for all fields, add the object to the pendingComplaintsList. Make sure you add them correctly along with the correct field names as used in the original code as those field names have beren used to print and identify the individual fields of each complaint
  71.  
  72. After finishing creation of list you can then set it as request attribute along with the correct name and dispatch the request to the same calling jsp page
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79. */
  80.  
  81. }
  82.  
  83.  
  84. // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  85. /**
  86. * Handles the HTTP <code>GET</code> method.
  87. *
  88. * @param request servlet request
  89. * @param response servlet response
  90. * @throws ServletException if a servlet-specific error occurs
  91. * @throws IOException if an I/O error occurs
  92. */
  93.  
  94. @Override
  95. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  96. throws ServletException, IOException {
  97. processRequest(request, response);
  98. }
  99.  
  100. /**
  101. * Handles the HTTP <code>POST</code> method.
  102. *
  103. * @param request servlet request
  104. * @param response servlet response
  105. * @throws ServletException if a servlet-specific error occurs
  106. * @throws IOException if an I/O error occurs
  107. */
  108. @Override
  109. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  110. throws ServletException, IOException {
  111. processRequest(request, response);
  112. }
  113.  
  114. /**
  115. * Returns a short description of the servlet.
  116. *
  117. * @return a String containing servlet description
  118. */
  119. @Override
  120. public String getServletInfo() {
  121. return "Short description";
  122. }// </editor-fold>
  123.  
  124. }
Add Comment
Please, Sign In to add comment