본문 바로가기
개발 업무(코딩)-개발자였을때 썼던..

public boolean preHandle(HttpServletRequest request, HttpServletResponse response) request 데이터가져오기

by 주용사 2023. 1. 9.
728x90

HttpServletRequest request가 어떻게 들어오는지 보고싶을때 사용가능.

하나하나 getParameter 처럼 받아오는게 아니고 json전체가 어떻게 들어오는지 볼수있음.

if ( request.getMethod().equals("POST") )
        {
            StringBuffer sb = new StringBuffer();
            BufferedReader bufferedReader = null;

            try {
                bufferedReader =  request.getReader() ; //new BufferedReader(new InputStreamReader(inputStream));
                char[] charBuffer = new char[128];
                int bytesRead;
                while ( (bytesRead = bufferedReader.read(charBuffer)) != -1 ) {
                    sb.append(charBuffer, 0, bytesRead);
                }

            } catch (IOException ex) {
                throw ex;
            } finally {
                if (bufferedReader != null) {
                    try {
                        bufferedReader.close();
                    } catch (IOException ex) {

                    }
                }
            }

            log.info("my test {}",  sb.toString());
        }
728x90