Several implementation methods about the Web Drop-down list

Source: Internet
Author: User
Tags add foreach define string
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



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.