在 Struts 2 中出现错误时保留用户输入的值
我有一个 JSP,其中包含一个文本框,
<input type="text" name="name" id="name" value="" maxlength="30" size="30"/>
<input type="text" name="captcha" id="captcha" value="" maxlength="20" size="20"/>
<s:if test="captchaErr != null">
<div class="errors"><s:property value="captchaErr" escape="false" /></div>
</s:if>
如果验证码输入不正确,我想保留用户在文本框中输入的值。我怎样才能在 Struts 2 中做到这一点?
谢谢!
I've a JSP which contains a text box
<input type="text" name="name" id="name" value="" maxlength="30" size="30"/>
<input type="text" name="captcha" id="captcha" value="" maxlength="20" size="20"/>
<s:if test="captchaErr != null">
<div class="errors"><s:property value="captchaErr" escape="false" /></div>
</s:if>
If the captcha is entered incorrectly, I want to retain the value which user has typed in the text box. How can I do that in Struts 2?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您选择不使用 S2 表单标签,则必须加载表单字段的值。您明确将其设置为空字符串,您应该使用操作属性加载它。
如果您在提交失败后重定向,则需要使用范围拦截器来保存操作属性。
If you choose not to use the S2 form tags then you must load the value of the form field. You're explicitly setting it to an empty string, you should be loading it with the action property.
If you're redirecting after submission failure you'll need to use the scope interceptor to save the action properties.