【发布时间】:2015-05-01 15:12:33
【问题描述】:
我正在使用 Struts2 <iterator> 标记在 JSP 中显示值。
方法被调用,但没有显示结果。它在控制台中打印我需要但不在 JSP 中的所有数据。
我打电话给localhost\listAddCompany.php
我做错了什么?
方法如下
listAllCompanys():
private List<Company> listAllCompanys;
Getters and setters...
public String listAllCompanys() throws Exception {
CompanyDaoHibernate dao = new CompanyDaoHibernate();
listAllCompanys = dao.getListOfCompanies();
System.out.println("Printing from CompanyManagmentAction...");
return SUCCESS;
}
struts.xml:
<action name="listAddCompany" class="com.handyman.web.CompanyManagementAction"
method="listAllCompanys">
<result name="success">companyAddUpdate.jsp</result>
</action>
这是我的
companyAddUpdate.jsp:
<h1>Add / Update Company</h1>
<s:form action="newCompany">
<!-- // id, Company_name, Address, Email, Website, Phone_number, Comment, Fax -->
<s:actionerror/>
<s:textfield name="company.companyName" label="Company's name" />
<s:textfield name="company.address" label="Address" />
<s:textfield name="company.email" label="Email" />
<s:textfield name="company.website" label="Website" />
<s:textfield name="company.phoneNumber" label="Phone Number" />
<s:textfield name="company.comment" label="Comment" />
<s:textfield name="company.fax" label="Fax" />
<s:submit value="Register" />
</s:form>
<h2>Contacts</h2>
<s:iterator value="listAllCompanys" var="company">
</s:iterator><table>
<tbody><tr>
<th>Company's name</th>
<th>Address</th>
<th>Email</th>
<th>Website</th>
<th>Phone Number</th>
<th>Comment</th>
<th>Fax</th>
</tr>
<tr>
<td><s:property value="companyName"></s:property></td>
<td><s:property value="address"></s:property></td>
<td><s:property value="email"></s:property></td>
<td><s:property value="website"></s:property></td>
<td><s:property value="phoneNumber"></s:property></td>
<td><s:property value="comment"></s:property></td>
<td><s:property value="fax"></s:property></td>
</tr>
</tbody></table>
【问题讨论】: