Advertisement
Guest User

Untitled

a guest
Jan 12th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. protected void processRequest(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
  2. response.setContentType("text/html;charset=UTF-8");
  3.  
  4. String searchQuery = "select * from jobs";
  5. DbUtil dbUtil = new DbUtil();
  6. ResultSet rs = DbUtil.readData(searchQuery);
  7. JSONArray listJobs = new JSONArray();
  8. try{
  9. while(rs.next()){
  10. //Retrieve by col and set to json obe
  11. JSONObject tempJob = new JSONObject();
  12. tempJob.put("jobCategory",jobCategory);
  13. listJobs.put(tempJob);
  14.  
  15. }
  16. try (PrintWriter out = response.getWriter()) {
  17. /* TODO output your page here. You may use following sample code. */
  18. response.setContentType("application/json");
  19. response.getWriter().print(listJobs);
  20. //out.print(listJobs);
  21. response.sendRedirect("searchresult.html");
  22. }
  23.  
  24. <html>
  25. <script src="http://code.jquery.com/jquery-latest.min.js"></script>
  26. <script type="text/javascript">
  27. $(document).ready(function() {
  28.            $.get('JobSearch',function(responseJson) {
  29.             if(responseJson!=null){
  30.                 $("#countrytable").find("tr:gt(0)").remove();
  31.                 var table1 = $("#countrytable");
  32.                 $.each(responseJson, function(key,value) {
  33.                      var rowNew = $("<tr><td></td><td></td>/tr>");
  34.                         rowNew.children().eq(0).text(value['jobPosition']);
  35.                         rowNew.children().eq(1).text(value['jobCountry']);
  36.                         rowNew.appendTo(table1);
  37.                 });
  38.                 }
  39.             });
  40.             $("#tablediv").show();              
  41. });
  42. </script>
  43.  
  44. <body>
  45. <div id="tablediv">
  46. <table cellspacing="0" id="countrytable">
  47.     <tr>
  48.         <th scope="col">Code</th>
  49.         <th scope="col">Name</th>      
  50.     </tr>
  51. </table>
  52. </body>
  53.  
  54. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement