web| dropdown | drop down list
Summarize the use of Drop-down boxes on the web
Get the data list from the database and put the data in the request using setattribute ("Alist", alist)
There are 2 properties in a (String id,string value)
1. Using the Jstl foreach method
<select name= "XX" ........>
<c:foreach items= "${alist}" var= "P" >
<c:choose>
<c:when test= "${xxx = = p.id}" >
<option value= ' <c:out value= ' ${p.id} '/> ' selected= ' selected ' >
<c:out value= "${p.value}"/>
</option>
</c:when>
<c:otherwise>
<option value= ' <c:out value= ' ${p.id} '/> ' >
<c:out value= "${p.value}"/>
</option>
</c:otherwise>
</c:choose>
<c:forEach>
</select>
2. Use the label of struts
Check out the API documentation for struts to see that there are 3 taglib available in the Select option.
The first direct use is to write all of the options in the middle.
Second: Put the option in a collection (use list here). In actual projects, more likely data comes from DB, files, and so on. This situation is used more.
Labelvaluebean is used here, it can not use, like
As long as the bean that is filled in alist has the value and id attribute, you can
Third, take this list as a property of the form.
Adds a alist setter and getter to the form. The form is treated as follows.
The list can be a form property.
F.setagelist (alist);
1. Get the data from the database, you should get the data in the action, put the data into the request
2. After the data is taken out and placed in a list or collection or map, I used to use the list
3. Data from list or other containers should be used
4.
5. Because you want to use these tags, you have to define Formbean
6. Take the data from the action, take list as an example
List = xxxxx;//from the database to get the data from the Drop-down list
Request.setattribute ("list", list);
On the page display
Add a little:
Since the data is to be fetched from the database, it is generally called DAO in the action, which is passed to the page as a property of the request, when the
In addition, if the data is not taken from the database, but the code is fixed, then generally put this into the actionform as a property on the page, when the general use of