微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Java-在一个jsp中使用多种形式

我在一个jsp页面上有两种形式.第一种形式不使用modelattribute,第二种形式使用modelattribute.问题是,如果我发布不使用modelattribute的第一个表单,则会声明我没有绑定modelattribute错误.

我已经在互联网上搜索解决方案,但是找不到有用的解决方案.

changeAddress.jsp

<form method="post">
     <input type="hidden" name="id" value="0" />
     <input type="submit" name="exist" value="send to this address" />
</form>
<form:form method="post" modelattribute="addressForm">
     <form:input path="street" />     
     <input type="submit" name="add" value="send to this address" />  
</form:form>

OrderController.java

@RequestMapping(value="changeAddress",method = RequestMethod.GET)
public ModelAndView showChangAddress(Model model)
{
     model.addAttribute("addressForm",new AddressForm());
     return new ModelAndView("body.changeaddress");
}

@RequestMapping(value="changeAddress",params="add",method = RequestMethod.POST)
public ModelAndView addChangAddress(@modelattribute("addressForm") @Valid AddressForm af,BindingResult result,Model model)
{
     System.out.println("a");
     return new ModelAndView("body.changeaddress");
}

@RequestMapping(value="changeAddress",params="exist",method = RequestMethod.POST)
public ModelAndView processChangAddress(@RequestParam(value="id") String id,Model model)
{
     System.out.println("b");
     return new ModelAndView("body.changeaddress");
}

恳求帮助:)

最佳答案
关于< form>的spring形式标签documentation .标签

This tag renders an HTML ‘form’ tag and exposes a binding path to inner tags for binding. It puts the command object in the PageContext so that the command object can be accessed by inner tags.

我认为您从Spring< form>起就不需要任何东西了.以您的第一种形式标记.因此,您可以使用简单的html表单代替:

<form method="post" action="...">
     <input type="hidden" name="id" value="0" />
     <input type="submit" name="exist" value="send to this address" />
<form>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐