-Please select-, which is actually the same as in html There is no difference, but JSP can use el expressions to achieve more convenient functions."/> -Please select-, which is actually the same as in html There is no difference, but JSP can use el expressions to achieve more convenient functions.">

Home  >  Article  >  Java  >  drop down list in jsp page

drop down list in jsp page

(*-*)浩
(*-*)浩Original
2019-05-20 16:53:313718browse

In the process of WEB development, we often encounter functional requirements for information modification. At this time, we provide the user with a JSP page that displays the current information and allows the user to reset the new value.

drop down list in jsp page

In this page, a drop-down list is generally indispensable. As for its processing method, I have thought of one before, and the idea is as follows: set a hidden field on the page to save the value passed from the background; then output the drop-down list on the page, and its value is the default at this time, that is, the first One item; get the value in the hidden field in the js code snippet and determine whether it is equal to the id value of the drop-down item in the loop. If equal, set the selected status of the item. Because this method is too cumbersome.

The following are two commonly used processing methods.

Method one:

<select id="user_id" name="user_id">
   	<c:forEach items="${users}" var="u">
   	<option value="${u.id }" <c:if test="${user.user_id==u.id}"><c:out value="selected"/></c:if>>
   	${u.name}
   	</option>
   	</c:forEach>
</select>

Method two:

<select id="projectPorperty" name="projectPorperty">
   	<option value="1">实施</option>
   	<option value="0">研发</option>
</select>
<script>
   	form.projectPorperty.value = '${user.projectPorperty}';
</script>

The above two methods have their own advantages and disadvantages. Choose as appropriate according to the situation!

The above is the detailed content of drop down list in jsp page. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn