读书人

spring表单异常信息显示

发布时间: 2012-06-28 15:20:03 作者: rapoo

spring表单错误信息显示

?

http://hi.baidu.com/danghj/blog/item/e567b5340e1677add0a2d3b6.html

?

只是为了记录,避免忘记

?

<form action="regDo.do" method="POST">

<table style="width: 100%; height: 100%" border="0" cellspacing="0" cellpadding="0">

<tr>

<th>邮箱</th>

<td><input name="termId" type="text" /></td>

<td><form:errors path="term.termId"></form:errors></td>

</tr>

<tr>

<th>密码</th>

<td><input id="termName" name="termName" type="text" /></td>

<td><form:errors path="term.termName"></form:errors></td>

</tr>

<tr>

<td> </td>

?

<td><input type="submit" name="btn_tijiao" value="提交注册" /></td>

</tr>

</table>

</form>

?

<form:form action="regDo.do" method="POST" commandName="term">

<table style="width: 100%; height: 100%" border="0" cellspacing="0" cellpadding="0">

<tr>

<th>邮箱</th>

<td><input name="termId" type="text" /></td>

<td><form:errors path="termId"></form:errors></td>

</tr>

<tr>

<th>密码</th>

<td><input id="termName" name="termName" type="text" /></td>

<td><form:errors path="termName"></form:errors></td>

</tr>

<tr>

<td> </td>

?

<td><input type="submit" name="btn_tijiao" value="提交注册" /></td>

</tr>

</table>

</form:form>

?

同时:

@ModelAttribute("term") Terms term, BindingResult result

?

?

?

在freemarker中

?

?

<form action="regDo.do" method="POST">

<table style="width: 100%; height: 100%" border="0" cellspacing="0" cellpadding="0">

<tr>

<th>termId---</th>

<td>

[@spring.formInput "term.termId" /]

</td>

<td>[@spring.showErrors "" /]</td>

</tr>

<tr>

<th></th>

<td>

</td>

<td>[@spring.showErrors "" /]</td>

</tr>

<tr>

<th>taxonomy</th>

<td>

[@spring.formInput "term.taxonomy" /]

</td>

<td></td>

</tr>

<tr>

<th>termName</th>

<td>

[@spring.formInput "term.termName" /]

</td>

<td>[@spring.showErrors "" /]</td>

</tr>

<tr>

<th></th>

<td>

</td>

<td>[@spring.showErrors "" /]</td>

</tr>

<tr>

<td> </td>

?

<td><input type="submit" name="btn_tijiao" value="提交注册" /></td>

</tr>

</table>

</form>

?

那么:

?

原来他是先根据[@spring.formInput "term.termId" /]然后才能输出[@spring.showErrors "" /]只要不再调用下一个[@spring.formInput那么即使多次调用[@spring.showErrors "" /]显示的信息依旧是上一个的
但是开始时候不能先<td>[@spring.showErrors "" /]</td>再[@spring.formInput "term.termId" /]
那么怎么才能够像jsp中有针对性的<td><form:errors path="term.termName"></form:errors></td>显示自己想要的信息呢?

读书人网 >软件架构设计

热点推荐