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.
*/ public void destroy() { super.destroy(); // Just puts "destroy" string in log // Put your code here } /** * The doGet method of the servlet.
* * 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(""); out.println(""); out.println(" A Servlet"); out.println(" "); out.print(" This is "); out.print(this.getClass()); out.println(", using the GET method"); out.println(" "); out.println(""); out.flush(); out.close(); } /** * The doPost method of the servlet.
* * 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 array = (ArrayList) 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.
* * @throws ServletException if an error occurs */ public void init() throws ServletException { // Put your code here } }