2
我想打電話從JSP(I幀)我的Spring MVC控制器和獲取瀏覽器通過客戶端發送的請求是語法不正確
400 Bad Request,The request sent by the client was syntactically incorrect()
這裏下面的錯誤是我的JQuery代碼發送請求到服務器
jQuery("#login").live('click', function(e) {
e.preventDefault();
jQuery.ajax({
url: "https://localhost:9002/myApp/springSecurity/login.json",
xhrFields: {
withCredentials: true
},
type: "POST",
crossDomain:true,
data: jQuery("#loginForm").serialize(),
contentType: "json",
success: function(data, status) {
alert(data);
alert(status);
if (data.loggedIn) {
// location.href = getHost() + '${ctx}/users';
//login_pannel
} else {
loginFailed(data);
}
},
error: loginFailed
});
});
這是我的控制器代碼
@Controller
@RequestMapping("springSecurity/login.json")
public class SpringSecurityLoginController
{
@RequestMapping(method = RequestMethod.POST)
@ResponseBody
public SpringSecurityLoginStatus login(@RequestParam("j_username") final String username,
@RequestParam("j_password") final String password, final HttpServletRequest request, final HttpServletResponse response)
{
LOG.info("Starting login process");
return springSecurityLoginService.login(username, password, request, response);
}
}
同時擊中提交按鈕我得到的服務器上沒有錯誤,但同時觀察瀏覽器控制檯輸出它顯示我下面的錯誤
"NetworkError: 400 Bad Request - https://localhost:9002/myApp/springSecurity/login.json"
這是Mozilla的響應頭錯誤信息
the request sent by the client was syntactically incorrect().
我不知道什麼導致了這種行爲。 此外,我正在使用Spring安全來處理身份驗證和授權。
編輯
我調試越來越發現,表單值沒有被提交到我的控制器,當我在我的控制器TEY檢查的j_username
和j_password
值來了空。
我甚至試過request.getParameter("param name");
但仍相同值來作爲空
記住你也可以贊成答案。 ;-) – Stealth
你能否提供完整的請求,如Firebug所示(請求+數據)? –
@Stealth:同意並完成。感謝您的快速回答 –