问题描述
我试图从JSP(I-Frame)调用我的Spring MVC控制器并在浏览器上收到以下错误
I am trying to call my Spring MVC controller from a JSP (I-Frame) and getting the following error on the browser
400 Bad Request,The request sent by the client was syntactically incorrect ()
这是我的JQuery用于向服务器发送请求的代码
here is my JQuery code to send request to the server
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);
}
}
点击提交按钮时我没有收到任何错误服务器,但在查看浏览器控制台输出时,它显示以下错误
While hitting the submit button i am getting no error on the server but while looking at browser console output it showing me the following error
"NetworkError: 400 Bad Request - https://localhost:9002/myApp/springSecurity/login.json"
这是来自Mozilla Response header的错误信息
This is Error information from Mozilla Response header
the request sent by the client was syntactically incorrect ().
我不确定导致此行为的原因。
此外,我使用Spring安全性来处理身份验证和授权。
I am not sure what causing this behavior.Additionally i am using Spring security to handle authentication and authorization.
编辑
我调试了更多并发现当我检查 j_username
和 j_password 在我的Controller中,tey将为null。
I debugged more and find out that the form values are not being submitted to my controller when i checked the value of j_username
and j_password
in my Controller tey are coming as null.
我甚至尝试过 request.getParameter(param name);
但仍然是相同的值为null
i even tried request.getParameter("param name");
but still same values are coming as null
推荐答案
在您的jQuery中,尝试将contentType更改为 dataType()。
In your jQuery, try changing "contentType" to "dataType" (more information here).
这篇关于客户端发送的请求在语法上是不正确的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!