今天开始在利用JSON向后台异步上传数据的时候,涉及到了一个图片的路径的回显工作!(以便在前台显示)是使用的AJAX异步提交并采用JSON数据!最后就涉及到了向前台发送JSON数据!情景描述清楚了,接下来直接上代码:<wbr style="line-height:28px; font-family:'Hiragino Sans GB W3','Hiragino Sans GB',Arial,Helvetica,simsun,宋体; font-size:16px"><div style="line-height:28px; font-family:'Hiragino Sans GB W3','Hiragino Sans GB',Arial,Helvetica,simsun,宋体; font-size:16px"> <pre class="prettyprint" style="border:1px solid rgb(136,136,136); padding:2px"><p style="padding-top:0px; padding-bottom:0px; margin-top:0px; margin-bottom:0px"><span style="font-family:comic sans ms; font-size:12px; line-height:22.75px">package cn.ilxy.web; import java.io.IOException; import javax.servlet.http.HttpServletResponse; /** * 异步返回各种格式数据:json xml text * * @author: Robert * @date: 2016年3月23日 */ public class ResponseUtils { private ResponseUtils() { } // 发送内容 "application/json;charset=UTF-8" public static void render(HttpServletResponse response, String contentType, String text) { response.setContentType(contentType); try { response.getWriter().write(text); } catch (IOException e) { e.printStackTrace(); } } // 发送的是JSON public static void renderJSON(HttpServletResponse response, String text) { render(response, "application/json;charset=UTF-8", text); } // 发送xml public static void renderXml(HttpServletResponse response, String text) { render(response, "application/xml;charset=UTF-8", text); } // 发送text public static void renderText(HttpServletResponse response, String text) { render(response, "application/plain;charset=UTF-8", text); } } </span></p><div><span style="font-family:comic sans ms; font-size:12px; line-height:22.75px"> </span></div></pre> <span style="white-space:pre"></span><span style="font-size:12px; line-height:22.75px">好了,工具类代码也贴了!各位看官有需要直接愉快的使用吧!</span> </div> <div><span style="font-size:12px; line-height:22.75px"><br></span></div> </wbr>
工具类积累(一)——Response向前台发送各种异步数据
最新推荐文章于 2022-12-29 10:10:19 发布