【问题标题】:(Spring controller) The requirement sent by the client was syntactically incorrect(Spring 控制器)客户端发送的需求在语法上不正确
【发布时间】:2013-05-18 14:56:00
【问题描述】:

我有以下jsp:

<form:form method="post" commandName="fare">
    <div><fmt:message key="createfares.name" /></div>
    <div><form:input path="name" type="text"></form:input> </div>
    <div><fmt:message key="createfares.amount" /></div>
    <div><form:input path="amount" type="number" min="0" step="0.01"></form:input></div>
    <div><fmt:message key="createfares.startDate" /></div>
    <div><input name="startDate" type="date"/> </div>
    <div><fmt:message key="createfares.endDate" /></div>
    <div><input name="endDate" type="date"/> </div>
    <div><fmt:message key="createfares.description" /></div>
    <form:textarea path="description" cols="125" /> 
     <div><form:errors path="*"/></div>
    <fmt:message key="modifyfare.note" />
    <div class="submit"><input name="submit" type="submit" value="<fmt:message key="tooltip.modifyfare" />"></div>
</form:form>

我有以下控制器:

@RequestMapping(value="/modify/{idFare}", method=RequestMethod.GET)
public String getModifyFare(@PathVariable String idFare, ModelMap model)

@RequestMapping(value="/modify/{idFare}", method=RequestMethod.POST)
public String postModifyFare(@PathVariable String idFare, @ModelAttribute("fare") @Valid Fare fare, ModelMap model,
        BindingResult result, final RedirectAttributes redirectAttributes,
        @RequestParam(required = false) String startDate, @RequestParam(required = false) String endDate)

GET 完美运行,但 POST 总是说“客户端发送的要求在语法上不正确”。

有人知道为什么会这样吗?

【问题讨论】:

  • 我已经删除了我在这篇文章中没有使用的“ModelMap模型”,它可以工作。

标签: spring jsp spring-mvc controller


【解决方案1】:

在控制器处理 POST 的方法的签名中,您同时拥有 RedirectAttributes 和 ModelMap。这两种类型用于在模型中存储变量。他们可能有冲突。尝试删除其中一个。

【讨论】:

    猜你喜欢
    • 2013-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-31
    • 1970-01-01
    • 2013-12-30
    相关资源
    最近更新 更多