客户端发送的请求在语法上不正确
我正在尝试从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 Response标头的错误信息
the request sent by the client was syntactically incorrect ().我不确定是什么原因导致了这种现象。另外,我正在使用Spring安全性来处理身份验证和授权。
我调试越来越发现,表单值没有被提交到我的控制器时我检查的价值j_username,并j_password在我的控制器TEY来了空。
我什至尝试过,request.getParameter("param name");但仍然有相同的值作为null
回答:
在您的jQuery中,尝试将“ contentType”更改为“
dataType”(更多信息,请参见)。
以上是 客户端发送的请求在语法上不正确 的全部内容, 来源链接: utcz.com/qa/431829.html





