java 客户端发送的请求在语法上不正确 - Spring mvc

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14194264/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 15:26:05  来源:igfitidea点击:

The request sent by the client was syntactically incorrect - Spring mvc

javaspringspring-mvc

提问by Java Questions

I am facing an issue with submitting the value to the controller in Spring MVC.

我在将值提交给 Spring MVC 中的控制器时遇到了问题。

When I call the controller with hrefit gets submitted to the controller method, I have submitted the following way :

当我调用控制器并将href其提交给控制器方法时,我提交了以下方式:

href='CIMtrek_Compliance_Daily_Shipments_Case_Pack_Calendar?date=<%=formatedDate%>'

href='CIMtrek_Compliance_Daily_Shipments_Case_Pack_Calendar?date=<%=formatedDate%>'

but when I submitted the same through javascript I get this exception The request sent by the client was syntactically incorrect.

但是当我通过javascript提交相同的内容时,我得到了这个异常 The request sent by the client was syntactically incorrect.

this is how I submit through javascript :

这就是我通过 javascript 提交的方式:

function getCasePackCalendar(date) {
     viewName ="CIMtrek_Compliance_Daily_Shipments_Case_Pack_Calendar?date="+date+" ";
     global.forms[0].action = viewName;
     global.forms[0].method = "GET"
     global.forms[0].submit()
}

and this is my controller method :

这是我的控制器方法:

@RequestMapping(value = "/CIMtrek_Compliance_Daily_Shipments_Case_Pack_Calendar", method = RequestMethod.GET)

        public ModelAndView  CIMtrek_Compliance_Daily_Shipments_Case_Pack_Calendar(@RequestParam("date") String date,HttpServletRequest request) {
            String[] data = new String[] {date};
        HttpSession session = request.getSession(true);
        String UserName = "";
        if(session.getAttribute("CIMtrek_UserName")!=null)
         UserName = session.getAttribute("CIMtrek_UserName").toString();
        ViewContent vc = new ViewContent();
        String HTML = vc
        .getContent(
        "com/cim/xml/CIMtrek_Compliance_Daily_Shipments_Case_Pack_sql.xml",
        "com/cim/xsl/view.xsl", "1 and 10","1","","0",UserName,data,"");

        List<String> ls = new ArrayList<String>();
            ls.add(HTML);
            logger.info("Welcome CIMtrek_Visitors_By___Unipart_Div__Date__Host___Visitor!");
            Map<String, Object> model = new HashMap<String, Object>();

        model.put("list", ls);
        model.put("iSPost", "N");

        logger.info("Welcome CIMtrek_Compliance_Daily_Shipments_Case_Pack!");

        return new ModelAndView("view", model);

        }   

this is how I have form

这就是我的形式

<form id="CIMtrek_Compliance_Daily_Shipments">
                                               <input type="hidden" id="CIMtrek_selectedIDs" name="CIMtrek_selectedIDs" value="" />
                                               <input type="hidden" id="CIMtrek_xmlData" name="CIMtrek_xmlData" value="" />
                                               <input type="hidden" id="CIMtrek_formName" name="CIMtrek_formName" value="CIMtrek_Compliance_Daily_Shipments" />
                                             </form>

what could be the problem.

可能是什么问题呢。

Please help me to find it.

请帮我找到它。

Best Regards.

最好的祝福。

回答by Boris Treukhov

Please use some debug tool(for example in Chrome use F12->Network tab, or use Firefox Firebug to see the request formed from the browser) In this case you are putting form parameters into the view name (even adding some strange space symbol in quotes after the parameters) in your client js - it does not seem to be right.

请使用一些调试工具(例如在 Chrome 中使用 F12->网络选项卡,或使用 Firefox Firebug 查看从浏览器形成的请求)在这种情况下,您将表单参数放入视图名称中(甚至在视图名称中添加一些奇怪的空格符号)参数后的引号)在您的客户端 js 中 - 它似乎不正确。

I suggest you to make a separate controller method that processes your form.

我建议您制作一个单独的控制器方法来处理您的表单。

In this case your form is incorrectly serialized(actually the correct html form serialization/parameter passing is regulated by several RFC).

在这种情况下,您的表单被错误地序列化(实际上,正确的 html 表单序列化/参数传递是由几个 RFC 规定的)。