Ajax常用工具

前端之家收集整理的这篇文章主要介绍了Ajax常用工具前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
import java.io.IOException; import java.io.PrintWriter; import java.util.List; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONObject; public class AjaxUtil { public static String AJAX_RETURN_OBJECT="ajaxReturnObject";//dont change this public static String AJAX_RETURN_VIEW="ajaxReturnView";//dont change this public static String bean2Json(Object bean){ JSONObject jsonobj=JSONObject.fromObject(bean); String jsonStr=jsonobj.toString(); return jsonStr; } public static void printf(AjaxResponseDTO bean,HttpServletResponse response) { response.setContentType("text/Xml;charset=UTF-8"); response.setHeader("Pragma","no-cache"); response.addHeader("Cache-Control","must-revalidate"); response.addHeader("Cache-Control","no-store"); response.setDateHeader("Expires",0); PrintWriter out = null; try { out = response.getWriter(); out.print(AjaxUtil.bean2Json(bean)); } catch (IOException e) { } finally { if (null != out) out.close(); } } public static String listToJson(List<?> list) { StringBuilder json = new StringBuilder(); json.append("["); if (list != null && list.size() > 0) { for (Object obj : list) { json.append(bean2Json(obj)); json.append(","); } json.setCharAt(json.length() - 1,']'); } else { json.append("]"); } return json.toString(); } } 原文链接:https://www.f2er.com/ajax/163708.html

猜你在找的Ajax相关文章