开发者

saving value selected in a list when submit button is clicked

开发者 https://www.devze.com 2022-12-28 02:16 出处:网络
In my JSP I have a dropdownlist and a submit button when clic开发者_开发技巧king the submit button I lose the value already selected in my list.

In my JSP I have a dropdownlist and a submit button when clic开发者_开发技巧king the submit button I lose the value already selected in my list. I am using the jstl because i need to construct other table corresponding the value selected in my list.For that I must call a submit button but the problem; it reset the value selected

I want to know if there is a way to save the value selected in my list even I click a submit button. I work with JSP and eclipse environment.

Thank you for your help.


You need to preset the inputs with the request parameter values. You can access parameter values in EL by ${param.name}. In case of dropdowns rendered by HTML <select> element, you need to set the selected attribute of the HTML <option> element in question. You can make use of the ternary operator in EL to print the selected attribute whenever the option value matches the request parameter value.

Basic example:

<select name="foo">
   <c:forEach items="${options}" var="option">
       <option ${param.foo == option ? 'selected' : ''}>${option}</option>
   </c:forEach>
</select>
0

精彩评论

暂无评论...
验证码 换一张
取 消