SPRING FRAMEWORK
spring mvc form post json submit 전
은호아빠
2022. 11. 7. 19:50
json 전송시 시크립트에서 json 을 만들어 전송을 하였는데
form에서 json 으로 전송할려면 enctype를 추가해주면 되었다.
<form id="frmFormSearch" enctype='application/json'method="post" action="${pageContext.request.contextPath}/주소">
<input type="text" class="before" id="before" name="before" placeholder="기존이름">
<input type="text" class="after" id="after" name="after" placeholder="변경이름">
<button type="submit" class="btn_search">적용</button>
</form>
서버단 컨트롤러는 이렇게 작성해주면 되었다.
//사이트 컨텍스트 변경시
@ResponseBody
@RequestMapping(value = "/경로", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
public CommonData image_path_update(@RequestParam Map<String, Object> map) throws Exception{
smsp.print_String("/경로");
Iterator<String> keys = map.keySet().iterator();
while( keys.hasNext() ){
String strKey = keys.next();
String strValue = (String) map.get(strKey);
//출력( strKey +":"+ strValue );
}
// 받아온 변수...별작업 없이 리턴
return map;
}