首页 > 代码库 > 读流的方式springMVC

读流的方式springMVC

去读:

String rsinfo = "";
        String content = "";
        HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
        try
        {
            BufferedInputStream buffer = new BufferedInputStream(request.getInputStream());
            BufferedReader  in = new BufferedReader(new InputStreamReader(buffer, "utf-8"));
            for (int m = 0; m < 10000; m++)
            {
                rsinfo = in.readLine();
                if (rsinfo == null) {
                    break;
                }
                content = content + rsinfo;
            }
        } catch (Exception ex) {

        }

------------------------------------------------------------------------------

去写:

((ServletWebRequest)RequestContextHolder.getRequestAttributes()).getResponse().setCharacterEncoding("UTF-8");
            PrintWriter writer = ((ServletWebRequest)RequestContextHolder.getRequestAttributes()).getResponse().getWriter();
            ((ServletWebRequest)RequestContextHolder.getRequestAttributes()).getResponse().setHeader("Access-Control-Allow-Origin", "*");
            writer.print(sucess);
            writer.close();

 

 

--------------------------------------------------------------------

 

读流的方式springMVC