类型:转载 责任编辑:asp.net 日期:2007/05/23
热门软件下载:
大家好,有个struts分页简单方法,在网上查的,怎么行不通,帮忙看看 ,有人用过这种方法吗,这方法行的通吗?我照着做的时候 提示:No getter method for property groupName of bean group 错误。
commons-beanutils 这个包我是更新换了的,为什么会提示 需要bean,getter方法了?
在网上查到的一个较好的解决方案:
As it happens, though, I just checked in a change in commons-beanutils
that can be used for this purpose, if youre using Struts 1.1.
Basically, theres now a really simple way to copy the contents of a
ResultSet into a list of DynaBeans. This really is a *copy* operation,
so you have to pay some performance and memory cost, but it lets you
pass the data without having to create custom beans, and without leaving
the ResultSet open.
Youll need to grab a very recent nightly build of commons-beanutils
from:
http://jakarta.apache.org/builds/jakarta-commons/nightly/commons-beanuti
ls
and replace your commons-beanutils.jar file if you want to try this.
> Please include the .java and .jsp code.
>
In your Java code, youd do something like this:
Connection conn = ...; // Get connection from the pool
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select custid, name from
customers");
RowSetDynaClass rsdc = new RowSetDynaClass(rs);
rs.close();
stmt.close();
... return connection to the pool ...
request.setAttribute("custoemrs", rsdc.getRows());
In your JSP page, treat this List of DynaBeans like you would any other
collection of beans, because all the Struts tags know how to deal with
DynaBeans.
<table>
<tr>
<th>Customer ID</th>
<th>Customer Name</th>
</tr>
<logic:iterate name="customers" id="customer">
<tr>
<td><bean:write name="customer" property="custid"/></td>
<td><bean:write name="customer" property="name"/></td>
</tr>
</logic:iterate>
</table>
See the updated Javadocs for commons-beanutils (included in the binary
distribution) for class org.apache.commons.beanutils.RowSetDataSource
for more information about this class.
网友回答: