不用返回值,向前端页面打印数据

使用HttpServletResponse对象响应,具体实现:

public static void print(HttpServletResponse response, String result) {
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json;charset=utf-8");
        PrintWriter out = null;
        try {
            out = response.getWriter();
            out.append(result);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (out != null) {
                out.close();
            }
        }
    }

你可能感兴趣的:(不用返回值,向前端页面打印数据)