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>