<select name="userCity">
<% for (int i = 0; i < cityList.size; i++) { %>
<option value="<%= i%>"> cityList.get(i)</option>
<% }%>
</select>
大概是这样的,没运行过。
<% for (int i = 0; i < cityList.size; i++) { %>
<option value="<%= i%>"> cityList.get(i)</option>
<% }%>
</select>
大概是这样的,没运行过。
<html:options name="bean" property="code" labelProperty="content" />
</html:select>
、、、、、、、、、、、、、、、、
Class City {
String code;
String content; ...
// setter() and getter();
...
} public Collection getCityList() {
ArrayList cityList = new ArrayList();
City city = new City(); city.setCode("01");
city.setContent("北京");
cityList.add(city); city.setCode("02");
city.setContent("上海");
cityList.add(city);
...
// and so on return (cityList);
}
给个我做的例子:
<html:select property="tsuchishoKbn" size="1" styleClass="select_box" value="<%=tsuchishoKbn%>">
<logic:iterate id="selectmenu" name="Chohyo" ype="jp.co.rkkcs.cas.GA_hoiku.hoiku.helper.ChohyoView">
<bean:define id="chohyocd" name="selectmenu"property="chohyoCd" type="java.lang.Integer"/>
<bean:define id="chohyo" name="selectmenu"property="chohyo" type="java.lang.String"/>
<html:option value="<%= String.valueOf(chohyocd)%>"><%= chohyo %></html:option>
</logic:iterate>
</html:select>看到了吗:
<logic:iterate STRUTS中用来做循环的,次数为Chohyo的SIZE
这个如何知道,它要选择的是CITY,有可能选择到省份呢。不行的下一个
根本无法编译
<html:options collection="nationality" property="nationalityId" labelProperty="nationality"/>
</html:select>
我如何将数据库信息显示为列表。
<bean:write name="pl"/>
<logic:iterate id="entity" name="pl" type="com.hazn.fs.enobj.TblCatalog">
<bean:define id="cataId" name="entity"property="cataId" type="java.lang.String"/>
<bean:define id="cataName" name="entity"property="cataName" type="java.lang.String"/>
<bean:define id="cataComemberPrice" name="entity"property="cataComemberPrice" type="java.lang.String"/>
<bean:define id="cataMemberPrice" name="entity"property="cataMemberPrice" type="java.lang.String"/>
<bean:define id="cataPictureid" name="entity"property="cataPictureid" type="java.lang.String"/>
<bean:write name="cataName"/>
</logic:iterate>
</logic:iterate>//对应方法
public Collection getProductList() {
product = new TblCatalog();
if (productList == null) {
productList = new ArrayList();
product.setCataName("北京");
productList.add(product);
product.setCataName("上海");
productList.add(product);
product.setCataName("天津");
productList.add(product);
product.setCataName("重庆");
productList.add(product);
product.setCataName("广州");
productList.add(product);
product.setCataName("深圳");
productList.add(product);
}
return productList;
}
<bean:write name="pl"/>
<logic:iterate id="entity" name="pl" type="com.hazn.fs.enobj.TblCatalog">
<bean:define id="cataId"
name="entity"property="cataId" type="java.lang.String"/>
<bean:define id="cataName"
name="entity"property="cataName" type="java.lang.String"/>
<bean:define id="cataComemberPrice"
name="entity"property="cataComemberPrice"
type="java.lang.String"/> <bean:write name="cataName"/>
</logic:iterate>
</logic:iterate>
去掉中间的logic:iterate,就可以显示对象。
com.hazn.fs.enobj.TblCatalog@12e7c6a[cataId=<null>,cataSerial=<null>] com.hazn.fs.enobj.TblCatalog@12e7c6a[cataId=<null>,cataSerial=<null>] com.hazn.fs.enobj.TblCatalog@12e7c6a[cataId=<null>,cataSerial=<null>] com.hazn.fs.enobj.TblCatalog@12e7c6a[cataId=<null>,cataSerial=<null>] com.hazn.fs.enobj.TblCatalog@12e7c6a[cataId=<null>,cataSerial=<null>] com.hazn.fs.enobj.TblCatalog@12e7c6a[cataId=<null>,cataSerial=<null>]
否则就有错误,请大家帮忙改一下。
<bean:define id="ksxqLabelValue" property="ksxqLabelValue" name="examActionForm" type="java.util.Collection"/>
<html:options collection="ksxqLabelValue" property="value" labelProperty="label"/>
</html:select>public class ExamActionForm extends ActionForm {
private String ksxq;
private Collection ksxqLabelValue =null; public String getKsxq() {
return ksxq;
}
public void setKsxq(String ksxq) {
this.ksxq = ksxq;
}
public Collection getKsxqLabelValue() {
return ksxqLabelValue;
}
public void setKsxqLabelValue(Collection ksxqLabelValue) {
this.ksxqLabelValue = ksxqLabelValue;
}
}//Collection contain LabelValueBean
public class LabelValueBean implements Serializable{public LabelValueBean()
{}
// ----------------------------------------------------------- Constructors
/**
* Construct a new LabelValueBean with the specified values.
*
* @param label The label to be displayed to the user
* @param value The value to be returned to the server
*/
public LabelValueBean(String label, String value) {
this.label = label;
this.value = value;
}
// ------------------------------------------------------------- Properties
/**
* The label to be displayed to the user.
*/
protected String label = null; public String getLabel() {
return (this.label);
} public void setLabel(String label) {
this.label=label;
} /**
* The value to be returned to the server.
*/
protected String value = null; public String getValue() {
return (this.value);
} public void setValue(String value) {
this.value=value;
}
楼上所说是显示SELECT.我现在要显示一个表格。
循环显示一个集合。
11月5号的问题如何来解决。
<bean:size id="size" name="students"/>
<logic:equal name="size" value="0">
</logic:equal><logic:notEqual name="size" value="0">
<table class="sort-table" id="table-1" cellspacing="0">
<thead>
<tr>
<td>学号</td>
<td>学生姓名</td>
<td>性别</td>
<td>出生年月</td>
<td>籍贯</td>
<td>民族</td>
</tr>
</thead>
<tbody>
<logic:iterate id="studentVO" name="students" type="cc.c37c.gedumis.bean.PStudent">
<tr>
<td><bean:write property="studentNumber" name="studentVO"/> </td>
<td><bean:write property="studentName" name="studentVO"/> </td>
<td><bean:write property="sexLabel" name="studentVO"/> </td>
<td><bean:write property="borntime" name="studentVO"/> </td>
<td><bean:write property="nativePlace" name="studentVO"/> </td>
<td><bean:write property="folkCode" name="studentVO"/> </td>
</tr>
</logic:iterate>
</tbody>
</table>