SpingMVC中利用BindingResult将错误信息返回到页面中。

ActionFrom中:

 private String name;

 private String password;

get()/set().......

JSP中:

<form:form > 

姓名:<form:input type="text" path="name" size="100" maxlength="100" cssStyle="ime-mode: active;"/>

<form:errors path="name" cssClass="errorClass"></form:errors>

密码:<form:input type="text"  path="password" size="100" maxlength="100" cssStyle="ime-mode: active;"/>

<form:errors path="password" cssClass="errorClass"></form:errors>

</from>

path的属性值和ActionForm中变量的一样的,大小写一致,这样才会找到form中出错的属性是哪个

后台Controller

@RequestMapping("/T51000TorokuEvAction")
    public String getToroku(@ModelAttribute("t51000ActionForm") T51000ActionForm t51000ActionForm){

if(name.equal("")){

result.rejectValue("name", errorcode,,defaultMessage);

}

}

这样就将错误信息显示到页面对应的属性的位置中了

相关文章:

  • 2021-10-15
  • 2021-10-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-31
  • 2021-12-13
  • 2021-09-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-21
  • 2021-12-13
  • 2021-06-27
  • 2021-06-03
相关资源
相似解决方案