I have a JSP/HTML form with text box and radio buttons. I am saving the data entered in the form in servlet context.
I am then jumping over to a new jsp/html page with the same form. Now I want to put the values entered previously back into the fields in this new form.
e.g. in text field user entered “ABC” which will be published in the new form using:
<INPUT TYPE="text" NAME="mytext" ID="mytext" value="<%=mytext %>">
How to do the same thing for the following: Drop down field, radio button field, check box field.
I have a group of radio button (e.g. in a search form the radio button values would be “begins with” or “contains” or “exact”. So one of the three will be saved in servlet context. How to republish the same in the new form ??
My radio button group is something like:
<TD valign="middle" align="left" width="100%" NOWRAP>
<INPUT type="radio" name="searchCriteria" id="searchCriteria" value="NAME_BEGINS" onfocus="onFocusNameBegins();"/><b>Begins With</b>
<INPUT type="radio" name="searchCriteria" id="searchCriteria" value="NAME CONTAINS" onfocus="onFocusNameContains();"/><b>Contains</b>
<INPUT type="radio" name="searchCriteria" id="searchCriteria" value="NAME_IS" onfocus="onFocusNameIs();"/><b>Exact Match</b>
</TD>
To the point, you just need to set the
selectedattribute in the<option>to preselect the dropdown option value and thecheckedattribute in<input type="radio|checkbox">to precheck the radio button or checkbox value.Assuming that your initial form look like this:
Then you can redisplay them by
${param.fieldname}in EL as follows:Note that I added
fn:escapeXml()there where you’re redisplaying user-controlled input inline of HTML. Otherwise you’re just creating a major XSS attack hole. Neither old fashioned Scriptlets nor the standard Java SE API have builtin XML escaping facilities to prevent XSS attacks.See also: