FormData
View:
fetch("/test.do", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"${_csrf.headerName}": "${_csrf.token}"
},
body: new URLSearchParams({
idx: idx
})
}).then(response => console.log(response));
Controller:
@RequestMapping(value = "/test.do")
public void test(HttpServletRequest request, HttpServletResponse response) throws NullPointerException, IOException, SQLException, Exception {
System.out.println(request.getParameter("idx"));
}
JSON
- 스프링: dispatch-servelt.xml
- 전자정부: egov-com-servelt.xml
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="webBindingInitializer">
<bean class="egovframework.com.cmm.web.EgovBindingInitializer"/>
</property>
<!-- @ResponseBody application/json 으로 변경 이거를 추가 해야함 -->
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
</list>
</property>
</bean>
View:
fetch("/test.do", {
method: "POST",
headers: {
"Content-Type": "application/json;charset=UTF-8",
"${_csrf.headerName}": "${_csrf.token}"
},
body: JSON.stringify({"idx":idx})
}).then(response => console.log(response));
Controller:
@RequestMapping(value = "/test.do", produces = "application/json; charset=utf8")
public void prtnrTrnsfer(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, String> param) throws NullPointerException, IOException, SQLException, Exception {
System.out.println(param.get("idx").toString());
}
'개발 > 트러블 슈팅' 카테고리의 다른 글
[LOG4J] log4j2 로그 두번 찍히는 오류 additivity="false" 안됨 (0) | 2022.11.10 |
---|---|
[MYBATIS] JSON_VALUE로 SELECT 받아올경우 오류 (0) | 2022.11.10 |
[Centos] https://vault.centos.org/6.10/os/x86_64/repodata/repomd.xml: [Errno 14] problem making ssl connection (0) | 2022.10.07 |
Could not convert socket to TLS (0) | 2022.10.06 |
unable to find valid certification path to requested target (0) | 2022.09.22 |