2014-05-14 2 views
1

POST를 사용하여 Ext JS에서 Spring 응용 프로그램으로 매개 변수를 보내려고합니다. 여기POST 및 ExtJS "Bad Request"POST 메서드 사용

@RequestMapping(value = "/unloadCatalog", method = RequestMethod.POST) 
public void unloadMappingCatalog(@RequestParam(required = true) String jsonString, 
           HttpServletRequest request, HttpServletResponse response) 
{ 

그리고 내선 JS 내가 그 매개 변수를 보낼 사용하고 니펫 : 여기에 내 컨트롤러입니다

var unloadData = Ext.encode(listObjects); 
Ext.Ajax.request({ 
    url:'content/unloadCatalog', 
    method: 'POST', 
    params:{ 
     jsonString: unloadData 
    }, 
    success: function(response, opts){ 
     // do something 
    } 
}); 

을하지만 몸의 데이터로 unloadData JSON 데이터를 보내는 경우

Ext.Ajax.request({ 
    url:'content/unloadCatalog', 
    method: 'POST', 
    jsonData: unloadData, 
    success: function(response, opts){ 
     // do something 
    } 
}); 

다음과 같이 내 컨트롤러를 변경하십시오.

@RequestMapping(value = "/unloadCatalog", method = RequestMethod.POST) 
public void unloadMappingCatalog(@RequestBody String jsonString, 
           HttpServletRequest request, HttpServletResponse response) 
{ 

모든 것이 정상적으로 작동합니다. 왜 첫번째 사건이 효과가 없습니까?

답변

2

이유는 기본적으로 데이터를 POST하면 데이터가 요청 본문에 래핑되고 콘텐츠 유형은 application/x-www-form-urlencoded

입니다.