Spring
[Spring] REST API 개발시 ajax로 DELETE,PATCH,PUT 요청시 파라미터 NULL문제
91cm
2018. 11. 18. 23:26
REST API를 개발하다가
아래와 같이 삭제 요청을 하다
서버쪽에서 데이터를 받아오려고하는대 계속 null값이 받아졌다.
1 2 3 4 5 6 7 8 9 10 11 | $.ajax({ url : "/board", type : "DELETE", dataType: "html", cache : false, data : { "boardSeq":boardSeq } }).done(function(result) { alert('삭제성공'); }); | cs |
1 2 3 4 5 6 7 8 9 | @ResponseBody @RequestMapping(value="/board", method= RequestMethod.DELETE) public String boardDelete(HttpServletRequest request, HttpServletResponse response, Authentication authentication , @RequestParam String boardSeq) throws Exception { System.out.println(boardSeq); // null return ""; } | cs |
[해결방법]
톰캣서버의 server.xml에 parseBodyMethods="POST,PUT,DELETE,PATCH" 추가해준다.
server.xml
1 | <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" parseBodyMethods="POST,PUT,DELETE,PATCH"/> | cs |