加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 01:22:29 所属栏目:大数据 来源:网络整理
导读:我在一个jsp页面上有两种形式.第一种形式不使用modelAttribute,第二种形式使用modelAttribute.问题是,如果我发布不使用modelAttribute的第一个表单,则会声明我没有绑定modelAttribute的错误. 我已经在互联网上搜索了解决方案,但是找不到有用的解决方案. chan

我在一个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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读