JSP(I-Frame)から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"
これはMozillaResponseヘッダーからのエラー情報です
the request sent by the client was syntactically incorrect ().
この動作の原因がわかりません。さらに、認証と承認を処理するためにSpringセキュリティを使用しています。
編集
j_username
さらにデバッグしたところ、コントローラーの値を確認したところ、フォームの値がコントローラーに送信されていないことがわかりましたj_password
。コントローラーのteyがnullになっています。
私も試しrequest.getParameter("param name");
ましたが、それでも同じ値がnullとして表示されます