日期:2014-05-17  浏览次数:20638 次

struts html标签自动保存提交的表单值。

?我们之前JSP提交值后如果还要取得值怎么做?

应该是取得action中设置的值,并把这个值给value.

<input type="text" name="user" value="<%=request.getAttribute("user")%>"/>

?

在使用struts时,使用了actionForm,action之后,我们知道会自动将actionForm设置到域中。可以这样做

<input type="user" value="${userForm.user}"/>

?

其中userForm是配置文件中对应的name="userForm",user为form中的属性。使用EL表达式。

?

实际上使用struts的html标签,因为它与form关联的相当紧密,我们只要下面的代码即可:

<html:text property="username" size="20" maxlength="20" ></html:text>

?

?

下面是login.jsp的代码:

<html:form action="login">
<table border="0" width="100%">
	<tr>
	<th align="right">UserName</th>
	<td align="left"><html:text property="username" size="20" maxlength="20" ></html:text></td>
	</tr>
	<tr>
		<th align="right">Password</th>
		<td align="left"><html:password property="password" size="20" maxlength="20" redisplay="false"></html:password></td>
	</tr>
	<tr>
		<td align="right"><html:submit>submit</html:submit></td>
		<td align="left"><html:reset>reset</html:reset></td>
	</tr>
	</table>
</html:form>

?上面的代码当客户输入用户名和密码之后,如果错误重新回到登录页面,那么上面的用户名自动保持与最后输入的一次一致。