當我輸入localhost:8080/ui /關於 時我調用了about.ftl頁面,並且我在裏面放了下面的代碼塊。通過SendToServlet()函數,我想給用戶的信息發送到我的控制器,這是OAuthController.javaSpring MVC Controller從來沒有從ajax中調用Post
function SendToServlet(){
$.ajax({
url: "localhost:8080/ui/about",
type: "POST",
data: JSON.stringify({ user:jsonObj}),
contentType: 'application/json',
success: function(result) {
alert(done);
},
error: function(xhRequest, ErrorText, thrownError) {
alert(JSON.stringify(jsonObj));
}
});
}
</script>
我的Spring MVC控制器類代碼具有下列實現 - 所有它確實是,它接受用戶的信息,然後設置當前用戶:
@Controller
@RequestMapping("/about")
public class OAuthController {
@RequestMapping(method = RequestMethod.POST)
@ResponseBody
public String post(@RequestBody String items, HttpServletRequest request, HttpServletResponse response)
{
String jsonResp = items;//sb.toString();
ArrayList<String> usercredentials = new ArrayList<String>();
usercredentials = parseJson(jsonResp);
UserMethods usermethods = new UserMethods();
usermethods.setCurrentUser (usercredentials);
response.setContentType("text/plain");
response.setCharacterEncoding("UTF-8");
return "{\"success\":\"\"}";
}
public ArrayList<String> parseJson(String json){
}
}
我的問題是,控制器永遠不會調用,實際上我從來沒有看到要通過Firebug的任何地方發送POST請求。我已經花了好幾天的時間,但仍然沒有運氣。你有什麼建議嗎?
HTTP狀態從服務器返回。它可能是一個400錯誤的請求? – Bart