过滤器输出返回值
Posted ynhk
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了过滤器输出返回值相关的知识,希望对你有一定的参考价值。
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();
以上是关于过滤器输出返回值的主要内容,如果未能解决你的问题,请参考以下文章