Select
Using a select list box in a JSP is as commonplace as usual!
Here are some of the things I've learned about this in the JSP page (usually struts+hebernate+spring):
I think there are several ways to get the select list box we want in the JSP
1: Using the normal select definition in HTML
<select name=select>
<option value=1>aa</option>
<option value=2>bb</option>
<option value=3>cc</option>
</select>
Of course this can be done, but once the relevant DB operation is used, the business in the code, persisted, the code that displays the processing parts will all mix together.
2: Through the logic tab of struts
<logic:iterate id=types name=cglist type=com.jbbis.netedu.common.dto.basecategorydto>
<option value=\ ' <bean:write name=types property=id/>\ ' >
<bean:write Name=types property=name/>
</option>
</logic:iterate>
The types represents a handle to the collection data, which is used in option. Type refers to the object in your collection. Some of the property values in the following option are actually the fields in this object. Like Property=id, property=. The name attribute in Name.logic:iterate is generally obtained from the session,request, so for cglist, it is likely that in your action, the following code:
Request.setattribute (Cglist,categorys);
Or
Session.setattribute (Cglist,categorys);
It is then printed out in the bean:write tag. This method is more convenient than the previous one for DB operations, but if you want to add some JS in the select is more trouble, such as to save its last choice, with JS to achieve a bit of trouble!
3: Through the html:select tag of struts, place this label inside the Html:form (personally think, the biggest advantage is that it can automatically save the last record!).
typeID a property in the actionform of your struts, typeids as an array of objects in Actionform. Name, IDs are the properties of the objects in this array. lable in Optionscollection represents the content to display in the Select, and value represents its corresponding value.
Note that the array of objects remember to initialize all, for example, if you define an array of objects with a length of 7 and you only instantiate 6, you will see a similar
Org.apache.jasper.JasperException:No Bean specified
The anomaly!
This approach is not only convenient for DB operations, but also good for saving records. When using JS in a JSP page in struts, there are always some unexpected errors (I don't know why).
The next time you meet a good strategy and put it up ...