123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- package BA_Control;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.ArrayList;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import com.helloBar.barBean;
- import com.helloBar.barDAO;
- import net.sf.json.JSONArray;
- public class helloPie extends HttpServlet {
- /**
- * Constructor of the object.
- */
- public helloPie() {
- super();
- }
- /**
- * Destruction of the servlet. <br>
- */
- public void destroy() {
- super.destroy(); // Just puts "destroy" string in log
- // Put your code here
- }
- /**
- * The doGet method of the servlet. <br>
- *
- * This method is called when a form has its tag value method equals to get.
- *
- * @param request the request send by the client to the server
- * @param response the response send by the server to the client
- * @throws ServletException if an error occurred
- * @throws IOException if an error occurred
- */
- public void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- response.setContentType("text/html");
- PrintWriter out = response.getWriter();
- out
- .println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
- out.println("<HTML>");
- out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
- out.println(" <BODY>");
- out.print(" This is ");
- out.print(this.getClass());
- out.println(", using the GET method");
- out.println(" </BODY>");
- out.println("</HTML>");
- out.flush();
- out.close();
- }
- /**
- * The doPost method of the servlet. <br>
- *
- * This method is called when a form has its tag value method equals to post.
- *
- * @param request the request send by the client to the server
- * @param response the response send by the server to the client
- * @throws ServletException if an error occurred
- * @throws IOException if an error occurred
- */
- public void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- //鍒涘缓浜嗕竴涓猙ardao鐨勫璞★紝barDAO涓昏鏄鏁版嵁搴撶殑杩炴帴鍜屽鏁版嵁搴撶殑鎿嶄綔
- barDAO bardao=new barDAO();
- //璋冪敤bardao鐨剆elect_all()鏂规硶鎶婁粠鏁版嵁搴撲腑璇诲彇鎵�鏈夌殑鏁版嵁杩斿洖鐨勬槸涓�涓狝rrayList锛孉rrayList閲岄潰鏀剧殑鏄竴涓猙arBean
- ArrayList<barBean> array = (ArrayList<barBean>) bardao.listAll();
- System.out.println("s"+array);
- //璁剧疆杩斿洖鏃剁殑缂栫爜鏍煎紡
- response.setContentType("text/html; charset=utf-8");
- //璋冪敤JSONArray.fromObject鏂规硶鎶奱rray涓殑瀵硅薄杞寲涓篔SON鏍煎紡鐨勬暟缁�
- JSONArray json=JSONArray.fromObject(array);
- System.out.println(json.toString());
- //杩斿洖缁欏墠娈甸〉闈�
- PrintWriter out = response.getWriter();
- out.println(json);
- out.flush();
- out.close();
- }
- /**
- * Initialization of the servlet. <br>
- *
- * @throws ServletException if an error occurs
- */
- public void init() throws ServletException {
- // Put your code here
- }
- }
|