工具类积累(一)——Response向前台发送各种异步数据

今天开始在利用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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值