码迷,mamicode.com
首页 > 其他好文 > 详细

过滤器输出返回值

时间:2019-09-16 10:09:20      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:ade   options   col   request   throws   app   return   type   ati   

 

 

    private void returnJson(HttpServletRequest request,ServletResponse response, ResultModel ResultModel) throws IOException {
        //把返回值输出到客户端
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        HttpServletResponse httpServletResponse = (HttpServletResponse) response;
        httpServletResponse.setHeader("Access-control-Allow-Origin", httpServletRequest.getHeader("Origin"));
        httpServletResponse.setHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS,PUT,DELETE");
        httpServletResponse.setHeader("Access-Control-Allow-Headers", httpServletRequest.getHeader("Access-Control-Request-Headers"));
        response.setContentType("application/json; charset=utf-8");
        response.setCharacterEncoding("UTF-8");
        ServletOutputStream outputStream = response.getOutputStream();
        outputStream.write(JsonTools.objToJson(ResultModel).getBytes());
        outputStream.flush();
        outputStream.close();

    }

 

过滤器输出返回值

标签:ade   options   col   request   throws   app   return   type   ati   

原文地址:https://www.cnblogs.com/ynhk/p/11525409.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!