【发布时间】:2012-06-18 11:18:21
【问题描述】:
我正在尝试从 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"
这是来自 Mozilla 响应标头的错误信息
the request sent by the client was syntactically incorrect ().
我不确定是什么导致了这种行为。 此外,我正在使用 Spring 安全性来处理身份验证和授权。
编辑
当我检查控制器中j_username 和j_password 的值是否为空时,我进行了更多调试,发现表单值没有提交给我的控制器。
我什至尝试过request.getParameter("param name");,但仍然有相同的值作为 null
【问题讨论】:
-
您能否提供如 Firebug 所示的完整请求(请求 + 数据)?
-
请记住,您也可以为答案投票。 ;-)
-
@Stealth:同意并完成。感谢您的快速回答
标签: jquery spring spring-mvc spring-security