JSP uses logic: iterate or HTML: optionscollection to display the list of objects in the action in a loop.

Source: Internet
Author: User

 

The code in action is as follows: <! --

Code highlighting produced by actipro codehighlighter (freeware)

Http://www.CodeHighlighter.com/

--> List alluser = This. getloginserviceimpl (). Find ();
Request. setattribute ("user", alluser );
Return Mapping. findforward ("listuser ");

Note: The user object has the ID and name attributes.

JSP display: method 1 <! --

Code highlighting produced by actipro codehighlighter (freeware)

Http://www.CodeHighlighter.com/

--> <HTML: Select Property = "school">
<HTML: option value = "">
<Bean: Message key = "login. Select"/>
</Html: Option>
<Logic: present name = "user">
<Logic: iterate id = "user" name = "user" offset = "0">
<Option value = "<Bean: write name =" user "property =" ID "/>">
<Bean: write name = "user" property = "name"/>
</Option>
</Logic: iterate>
</Logic: Present>
</Html: Select>

JSP display: method 2 <! --

Code highlighting produced by actipro codehighlighter (freeware)

Http://www.CodeHighlighter.com/

--> <HTML: Select Property = "school">
<HTML: optionscollection name = "user" value = "ID" label = "name"/>
</Html: Select>

Optionscollection label usage:
Like the options tag, the optionscollection tag can obtain the option tag/value pair from a set or an object that contains the set. In both cases, the set or the object containing the set must be a scope object, otherwise the custom tag will not be able to access it.

1. Use with objects containing the set
For example, the userform action form has an arraylist-type userlist attribute, corresponding set and get methods. After setting userform in the action, request. setattribute ("userform", userform );
On the JSP page: <! --

Code highlighting produced by actipro codehighlighter (freeware)

Http://www.CodeHighlighter.com/

--> <HTML: Select Property = "school">
<HTML: optionscollection name = "userform"
Property = "userlist"/>
</Html: Select>

2. Use with the set
Action <! --

Code highlighting produced by actipro codehighlighter (freeware)

Http://www.CodeHighlighter.com/

--> Arraylist userlist = new arraylist ();
Userlist. Add (New labelvaluebean ("1", "Haha "));
Userlist. Add (New labelvaluebean ("2", "dada "));
Userlist. Add (New labelvaluebean ("3", "Xiaoxiao "));
Request. setattribute ("userlist", userlist );

JSP page <! --

Code highlighting produced by actipro codehighlighter (freeware)

Http://www.CodeHighlighter.com/

--> <HTML: Select Property = "school">
<HTML: optionscollection name = "userlist"
Label = "label" value = "value"/>
</Html: Select>

Related Article

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.