Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 客户端发送的请求在语法上不正确_Spring_Jsp_Validation - Fatal编程技术网

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

Spring 客户端发送的请求在语法上不正确,spring,jsp,validation,Spring,Jsp,Validation,我有两个使用spring框架的非常相似的web函数,函数1点击“客户端发送的请求在语法上不正确”,而函数2运行良好。我在下面展示一个不起作用的,希望有人能帮助我 功能1: <form:form id="sform" action="DealMaintEdit.htm" method="POST" commandName="dmForm"> <table border="1"> <tr><td><spring:message code=

我有两个使用spring框架的非常相似的web函数,函数1点击“客户端发送的请求在语法上不正确”,而函数2运行良好。我在下面展示一个不起作用的,希望有人能帮助我

功能1:

<form:form id="sform" action="DealMaintEdit.htm" method="POST" commandName="dmForm">
<table border="1">
    <tr><td><spring:message code="label.DealID"/></td>
        <td><form:input path="deal.dealId" readonly="true" size="6"/></td>
    </tr>
    <tr><td><spring:message code="label.Code"/></td>
        <td><form:input path="deal.stkCode"  maxlength="5" size="6"/>
            <form:errors path="deal.stkCode" cssClass="error"/></td>
    </tr>    .....other fields skipped....
</table>
<form:hidden path="mode"/>
<form:hidden path="butt" value="Save"/>
<input form="sform" type="submit" value="<spring:message code="label.Save"/>"/>
</form:form>
功能1控制器:

@RequestMapping(value = "/DealMaintEdit.htm")
public String dealMaintEdit(@ModelAttribute("dmForm") @Valid DealMaintForm form,
     @RequestParam("butt") String butt, BindingResult result, Map model) {
我在控制器中有if(result.hasErrors()),但在遇到错误之前它没有执行

功能1交易:

public class Deal implements Serializable {
    private Long dealId;
    private DealType type;
    @NotNull
    @Min(1)
    @Max(99999)
    private int stkCode;
......
有趣的是,如果存在验证错误,它会在到达控制器方法之前命中语法错误。假设我在stkCode中输入2可以正常工作,但是如果我将stkCode中的@Min(1)更改为@Min(5),那么在stkCode中输入2将在语法上不正确。其他字段是相同的

我的另一个工作的web表单如下所示。 功能2:

<form:form action="StockMaint2Edit.htm" method="POST" commandName="smForm">
<form:hidden path="mode"/>
<form:hidden path="stk.id"/>
    <table border="1">
        <tr>
            <td><spring:message code="label.Code"/></td>
            <td><form:input path="stk.code"/><form:errors path="stk.code" cssClass="error"/></td>
        </tr>
        <tr>
            <td><spring:message code="label.Name"/></td>
            <td><form:input path="stk.name" /><form:errors path="stk.name" cssClass="error"/></td>
        </tr>
    </table>
<form:hidden path="butt" value="Save"/>
<input type="submit" value="<spring:message code="label.Save"/>"/>
</form:form>
功能2控制器

@RequestMapping(value = "/StockMaint2Edit.htm")
public String stockMaintEdit(@ModelAttribute("smForm") @Valid StockMaintForm2 form,
BindingResult result, Map model) {
    if (result.hasErrors()) {
        System.out.println("edit has errors");
        List<FieldError> errList = result.getFieldErrors();
        for (FieldError fe : errList) {
......
功能2在正确显示所有验证错误消息的情况下工作。没有语法错误。
对它们进行了多次比较,仍然无法发现差异和问题的原因。请告诉我是否需要提供更多信息。

我想这会导致错误

<form:hidden path="butt" value="Save"/>
在您的
函数1 JSP中


正如您使用的
spring:form
标记一样<代码>对接在请求中不明确可用。您需要从
模型属性
获取它,或者您可以简单地使用html标记创建输入字段。因此,它将在
请求中可用,我看到您实际上正在合并方法上的注释:

你能试着在那里换行吗

public class Stock implements Serializable {

    private static final long serialVersionUID = 1L;
    private Long id;

    @NotNull
    @Min(1)
    @Max(99999)
    private int code;

    @NotBlank
    private String name;
....

谢谢你的回复。我应该单独回复,但在添加第一条评论后,我无法添加更多评论。所以我在这里回答。在你的帮助下,我专注于“屁股”。因为它同时在表单和参数中,所以我删除@RequestParam并从表单中获取它,然后它就可以工作了

@RequestMapping(value = "/DealMaintEdit.htm")
public String dealMaintEdit(@ModelAttribute("dmForm") @Valid DealMaintForm form,
    BindingResult result, Map model) { ......
@SergeBallesta,试过你的建议,把屁股移到末端,它也起作用了。如何添加您的有用评论

@RequestMapping(value = "/DealMaintEdit.htm")
public String dealMaintEdit(@ModelAttribute("dmForm") @Valid DealMaintForm form,
    BindingResult result, Map model, @RequestParam("butt") String butt) {   ....
@SanKrish尝试了普通的html“隐藏”,但不起作用。此外,由于问题缺少param,而我的@RequestParam是冗余的,所以我尝试了这个方法

@RequestMapping(value = "/DealMaintEdit.htm")
public String dealMaintEdit(@ModelAttribute("dmForm") @Valid DealMaintForm form,
   @RequestParam("butt2") String butt2, BindingResult result, Map model) {   ....
在jsp中

<form:form id="sform" action="DealMaintEdit.htm?butt2=abcd" method="POST" commandName="dmForm">

它也不起作用。虽然问题有些如何解决,但仍有两个问题:

  • 为什么“butt2”仍然有语法错误
  • 如果原始问题是由于缺少参数造成的,为什么只有在存在验证错误时才会发生
    不确定它是否相关,但
    BindingResult
    应立即跟随
    ModelAttribute
    。如前所述,spring将其用于
    @RequestParam(“butt”)字符串butt
    ..@SergeBallesta为什么
    BindingResult
    modeldattribute
    注释一起使用时会有表单值?你确定这会导致客户端发送的请求语法错误吗?
    @RequestMapping(value = "/DealMaintEdit.htm")
    public String dealMaintEdit(@ModelAttribute("dmForm") @Valid DealMaintForm form,
        BindingResult result, Map model) { ......
    
    @RequestMapping(value = "/DealMaintEdit.htm")
    public String dealMaintEdit(@ModelAttribute("dmForm") @Valid DealMaintForm form,
        BindingResult result, Map model, @RequestParam("butt") String butt) {   ....
    
    @RequestMapping(value = "/DealMaintEdit.htm")
    public String dealMaintEdit(@ModelAttribute("dmForm") @Valid DealMaintForm form,
       @RequestParam("butt2") String butt2, BindingResult result, Map model) {   ....
    
    <form:form id="sform" action="DealMaintEdit.htm?butt2=abcd" method="POST" commandName="dmForm">