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!
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.