Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. public class ServletName extends HttpServlet{
  2.  
  3. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  4.  
  5. PrintWriter out = response.getWriter();
  6. ArrayList al= new ArrayList<Employee>();
  7. al = ApproverDao.requestGetter();
  8. String json = new Gson().toJson(al);
  9. response.setContentType("application/json");
  10. response.setCharacterEncoding("UTF-8");
  11. out.write(json);
  12. }
  13.  
  14. <script type="text/javascript">
  15. $(document).ready(function() {
  16. $("#approve_btn").click(function() {
  17. var remarks =$('[name="result_decide"]').val();
  18. $.post("/ServletName/decision.do", {result_decide : remarks},
  19. function(responseJson) {
  20. var $table = $('<table>').appendTo($('#tabs-4'));
  21. $.each(responseJson, function(index, employee) {
  22. $('<tr>').appendTo($table)
  23. .append($('<td>').text(employee.eName))
  24. .append($('<td>').text(employee.fromDate))
  25. .append($('<td>').text(employee.toDate));
  26.  
  27. });
  28. });
  29. });
  30. </script>
  31.  
  32. class Employee{
  33. private String eName;
  34. private Date fromDate;
  35. private Date toDate;
  36. //setters and getters
  37. }
  38.  
  39. $.getJSON('/ServletName/decision', function(data) {
  40. var table = $('<table/>').appendTo($('.adminlist'));
  41. $('<tr/>').appendTo(table)
  42. .append($('<th/>').text("Employee Name"))
  43. .append($('<th/>').text("To Date"))
  44. .append($('<th/>').text("From Date"));
  45.  
  46. data.forEach(function(x, i) {
  47. var stat = data[i];
  48. $('<tr/>').appendTo(table)
  49. .append($('<td/>').text(stat.eName))
  50. .append($('<td/>').text(stat.fromDate))
  51. .append($('<td/>').text(stat.toDate));
  52. });
  53. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement