ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • c:import 사용 시 주의사항 (Request method 'POST' not supported)
    Etc 2016. 7. 14. 19:54

    c:import 사용 시 주의사항 (Request method 'POST' not supported)

    language/java 2014.05.16 17:07

    Controller의 requestMapping 애노테이션에 등록되어 있는 /miniList URL은 GET 방식만 허용할 수 있게 다음과 같이 정의되어 있고,

    @RequestMapping(value = "/miniList", method = {RequestMethod.GET})


    커스텀 태그는 다음과 같이 jsp 코드안에 추가되어 있다.

    <c:import url="/miniList" />


    위의 코드를 보면 일단 HTTP GET 방식으로의 요청으로만 /miniList 를 처리할 수 있을 것이다.


    허나 아래 시퀀스 다이어그램과 같이 /account 요청 시 POST 방식으로 호출하게 되면 /account 의 결과 jsp 안에 있는 <c:import url="/miniList" /> 커스텀 태그 처리 동작이 최초 요청의 method 방식과 동일한 POST 방식으로 서버에 요청을 보낸다.



    결국 POST 방식으로의 요청을 처리할 수 없다는 예외 메세지를 만나게 된다.

    [2014-05-13 13:18:25 DEBUG o.s.w.s.DispatcherServlet][823] - DispatcherServlet with name 'dispatcher' processing POST request for [/miniList]

    [2014-05-13 13:18:25 DEBUG o.s.w.s.DispatcherServlet][831] - Taking snapshot of request attributes before include

    [2014-05-13 13:18:25 DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping][220] - Looking up handler method for path /miniList

    [2014-05-13 13:18:25 DEBUG o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver][132] - Resolving exception from handler [null]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported

    [2014-05-13 13:18:25 WARN  o.s.w.s.PageNotFound][194] - Request method 'POST' not supported



    커스텀 태그 동작 방식이 이런 줄은 오늘 알게 되었다.

    이를 해결하기 위해서는 다음과 같이 GET, POST 요청 모두를 수용할 수 있도록 Controller 코드를 다음과 같이 수정해 주면 된다.

    @RequestMapping(value = "/miniList", method = {RequestMethod.GET, RequestMethod.POST})


    또 한가지 유념해야 할 부분은 위의 시퀀스 다이어그램 1번과 5번의 HTTP request 객체는 서로 다르다는 것이다.

    만약 5번 request 객체에 특정 데이터를 setAttribute 하여도 1번 request 에서는 getAttribute를 이용하여 값을 가져올 수 없다.

    1번 request : org.apache.catalina.connector.RequestFacade@74aff38f

    5번 request : org.apache.catalina.core.ApplicationHttpRequest@2e73997d

    'Etc' 카테고리의 다른 글

    면접 꿀팁  (0) 2016.08.09
    안드로이드 성능 최적화 참고하기 좋은 사이트  (0) 2016.07.20
    자바 Vector VS ArrayList VS LinkedList  (0) 2016.06.29
    joseon-address.js API  (0) 2016.06.10
    자바 개행문자 제거(줄바꿈/행구분)  (0) 2016.06.07
Designed by Tistory.