helloLine.java 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package helloLine;
  2. import java.io.IOException;
  3. import java.io.PrintWriter;
  4. import java.util.ArrayList;
  5. import javax.servlet.ServletException;
  6. import javax.servlet.http.HttpServlet;
  7. import javax.servlet.http.HttpServletRequest;
  8. import javax.servlet.http.HttpServletResponse;
  9. import net.sf.json.JSONArray;
  10. public class helloLine extends HttpServlet {
  11. /**
  12. * Constructor of the object.
  13. */
  14. public helloLine() {
  15. super();
  16. }
  17. /**
  18. * Destruction of the servlet. <br>
  19. */
  20. public void destroy() {
  21. super.destroy(); // Just puts "destroy" string in log
  22. // Put your code here
  23. }
  24. /**
  25. * The doGet method of the servlet. <br>
  26. *
  27. * This method is called when a form has its tag value method equals to get.
  28. *
  29. * @param request the request send by the client to the server
  30. * @param response the response send by the server to the client
  31. * @throws ServletException if an error occurred
  32. * @throws IOException if an error occurred
  33. */
  34. public void doGet(HttpServletRequest request, HttpServletResponse response)
  35. throws ServletException, IOException {
  36. response.setContentType("text/html");
  37. PrintWriter out = response.getWriter();
  38. out.flush();
  39. out.close();
  40. }
  41. /**
  42. * The doPost method of the servlet. <br>
  43. *
  44. * This method is called when a form has its tag value method equals to post.
  45. *
  46. * @param request the request send by the client to the server
  47. * @param response the response send by the server to the client
  48. * @throws ServletException if an error occurred
  49. * @throws IOException if an error occurred
  50. */
  51. public void doPost(HttpServletRequest request, HttpServletResponse response)
  52. throws ServletException, IOException {
  53. lineDAO linedao=new lineDAO();
  54. ArrayList<lineBean> array = (ArrayList<lineBean>) linedao.listAll();
  55. System.out.println("s"+array);
  56. response.setContentType("text/html; charset=utf-8");
  57. JSONArray json=JSONArray.fromObject(array);
  58. System.out.println(json.toString());
  59. PrintWriter out = response.getWriter();
  60. out.println(json);
  61. out.flush();
  62. out.close();
  63. // lineDAO2 linedao2=new lineDAO2();
  64. // ArrayList<lineBean> array2 = (ArrayList<lineBean>) linedao2.listAll();
  65. // System.out.println("s"+array2);
  66. // response.setContentType("text/html; charset=utf-8");
  67. // JSONArray json2=JSONArray.fromObject(array2);
  68. // System.out.println(json2.toString());
  69. // PrintWriter out2 = response.getWriter();
  70. // out2.println(json2);
  71. // out2.flush();
  72. // out2.close();
  73. }
  74. /**
  75. * Initialization of the servlet. <br>
  76. *
  77. * @throws ServletException if an error occurs
  78. */
  79. public void init() throws ServletException {
  80. }
  81. }