拦截器中通过response返回JSON数据
来源:互联网 发布:td什么意思网络用语 编辑:程序博客网 时间:2024/05/21 19:13
原文地址: http://blog.csdn.net/u012201619/article/details/75156707
做接口的拦截器时,需在拦截器中通过response返回接口是否允许调用的JSON信息:
response.setCharacterEncoding("UTF-8"); response.setContentType("application/json; charset=utf-8");PrintWriter out = null ;try{ JSONObject res = new JSONObject(); res.put("success","false"); res.put("msg","xxxx"); out = response.getWriter(); out.append(res.toString()); return false;}catch (Excepton e){ e.printStackTrace(); response.sendError(500); return false;}
需要导入的依赖
http://mvnrepository.com/artifact/org.json/json
http://mvnrepository.com/artifact/org.json/json/20171018
另一片类似的文章
原文:http://blog.csdn.net/a379850992/article/details/54582760
怎么在SpringMvc拦截器或者request中取得前端传递过来的Json数据
public String readJSONString(HttpServletRequest request){ StringBuffer json = new StringBuffer(); String line = null; try { BufferedReader reader = request.getReader(); while((line = reader.readLine()) != null) { json.append(line); } } catch(Exception e) { System.out.println(e.toString()); } return json.toString(); }}
之后 再转成 jsonObject 对象。就可以取到值了
还有一点 要注意 编码格式.
给前端返回值可用response.getWriter().write("此处为内容");
request.getParameter()、 request.getInputStream()、request.getReader()这三种方法是有冲突的,因为流只能被读一次。
阅读全文
0 0
- 拦截器中通过response返回JSON数据
- 拦截器中通过response返回JSON数据
- shiro拦截器,返回json数据
- Response JSON数据返回(备忘)
- 关于response返回json格式的数据
- Response 组装JSON数据返回(备忘)
- 使用参数拦截器通过注解直接从JSON对象中获取数据
- Strust2 拦截器处理返回自定义json格式数据
- Spring拦截器实现controller层json数据返回
- response返回的json数据的list对象返回错误
- struts2拦截器如何返回json数据?如何使用Jquery(ExtJs)接收拦截器返回的数据?
- Response 返回xml,json
- Response 异步返回各种格式数据:json xml text Protobuf
- spring拦截器拦截request与response业务数据
- SpringMVC 中 返回JSON 数据
- IDEA中通过Map返回JSON字符串
- java 通过发送json,post请求,返回json数据
- struts2中通过拦截器实现对返回结果的过滤
- IO流介绍
- c语言----栈帧
- 609. Find Duplicate File in System
- 体验最新版AndroidStudio3.0
- leetcode 475. Heaters 求解左近邻和右近邻
- 拦截器中通过response返回JSON数据
- JQ插件封装(jq_ui风格)
- 12-12 Never too late too learn
- 设计模式知识连载(4)---封装_3:创建对象的安全模式
- Android开发之如何自定义垂直方向的SeekBar
- 微信小程序--登陆接口
- android 监听没有全部运行或被堵塞
- POI导出EXCEL文档、水平垂直居中、表头添加颜色
- vue--切换class