jsp编写分页显示时使用setproperty出错!!!急!!!

dandan880107 2011-03-05 09:02:52
我的分页显示java代码:
package database.operation;
import java.sql.*;
import com.sun.rowset.*;

/**
* 分页显示
*/
public class ShowRecordByPage
{ int pageSize=10; //每页显示的记录数
int pageAllCount=0; //分页后的总页数
int showPage=1; //当前显示页
StringBuffer presentPageResult; //显示当前页的内容
CachedRowSetImpl rowSet; //用于存储ResultSet对象
String databaseName=""; //数据库的名字
String tableName=""; //表名
String user=""; //用户
String password=""; //密码
String ziduan[]=new String[100]; //字段
int num=0; //字段个数
public ShowRecordByPage()
{ presentPageResult=new StringBuffer();
try{ //Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
}
catch(Exception e){ }
}
public void setPageSize(int size)
{ pageSize=size;
num=0;
String
//uri="jdbc:odbc:emp";
uri="jdbc:odbc:"+databaseName;
//uri="jdbc:sqlserver://localhost:1433;DatabaseName=job";
try{ Connection con=DriverManager.getConnection(uri,user,password);
DatabaseMetaData metadata=con.getMetaData();
ResultSet rs1=metadata.getColumns(null,null,"emp",null);
//ResultSet rs1=metadata.getColumns(null,null,tableName,null);
int k=0;
while(rs1.next())
{ num++;
ziduan[k]=rs1.getString(4);
k++;
}
Statement sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
//ResultSet rs=sql.executeQuery("SELECT * FROM emp");
ResultSet rs=sql.executeQuery("SELECT * FROM "+tableName);
rowSet=new CachedRowSetImpl();//创建行集对象
rowSet.populate(rs);
con.close();
rowSet.last();
int m=rowSet.getRow();
int n=pageSize;
pageAllCount=((m%n)==0)?(m/n):(m/n+1);
}
catch(Exception exp){}
}
public int getPageSize()
{ return pageSize;
}
public int getPageAllCount()
{ return pageAllCount;
}
public void setShowPage(int n)
{ showPage=n;
}
public int getShowPage()
{ return showPage;
}
public StringBuffer getPresentPageResult()
{ if(showPage>pageAllCount)
showPage=1;
if(showPage<=0)
showPage=pageAllCount;
presentPageResult=show(showPage);
return presentPageResult;
}
public StringBuffer show(int page)
{ StringBuffer str=new StringBuffer();
str.append("<table border=1>");
str.append("<tr>");
for(int i=0;i<num;i++)
{ str.append("<th>"+ziduan[i]+"</th>");
}
str.append("</tr>");
try{ rowSet.absolute((page-1)*pageSize+1);
for(int i=1;i<=pageSize;i++)
{ str.append("<tr>");
for(int k=1;k<num;k++)
{ str.append("<tr>"+rowSet.getString(k)+"</td>");
}
str.append("</tr>");
rowSet.next();
}
}
catch(SQLException exp){}
str.append("</table>");
return str;
}
public void setDataBaseName(String s)
{ databaseName=s.trim();
}
public String getDatabaseName()
{ return databaseName;
}
public void setTableName(String s)
{ tableName=s.trim();
}
public String getTableName()
{ return tableName;
}
public void setPassword(String s)
{ password=s.trim();
}
public String getPassword()
{ return password;
}
public void setUser(String s)
{ user=s.trim();
}
public String getUser()
{ return user;
}
}
我的showByPage。jsp代码
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.sql.*" %>
<%@ page import="database.operation.*" %>
<jsp:useBean id="look" class="database.operation.ShowRecordByPage" scope="session" />
<jsp:setProperty name="look" property="databaseName" value="emp"/>
<jsp:setProperty name="look" property="tableName" value="emp"/>
<jsp:setProperty name="look" property="user" param="sa"/>
<jsp:setProperty name="look" property="password" param="sa"/>
<jsp:setProperty name="look" property="pageSize" value="2"/>
<HTML>
<BODY>
数据库
<jsp:getProperty name="look" property="databaseName" />中
<jsp:getProperty name="look" property="tableName"/>表的记录将被分页显示。
<br><br>
共有<jsp:getProperty name="look" property="pageAllCount"/>页
<br><br>
每页最多显示<jsp:getProperty name="look" property="pageSize"/>条记录
<jsp:setProperty name="look" property="showPage"/>
<jsp:getProperty name="look" property="presentPageResult"/>
<br>
当前显示第<jsp:getProperty name="look" property="showPage"/>页
<br>单击"前一页"或"后一页"按钮查看记录
<table>
<tr>
<td>
<form action="">
<input type=hidden name="showPage" value="<%=look.getShowPage()-1%>">
<input type=submit name="g" value="前一页">
</form>
</td>
<td>
<form action="">
<input type=hidden name="showPage" value="<%=look.getShowPage()+1%>">
<input type=submit name="g" value="后一页">
</form>
</td>
<td>
<form action="">
输入页码:<input type=text name="showPage" size=5>
<input type=submit name="g" value="提交">
</form>
</td>
</tr>
</table>
</Body>
</HTML>
网页错误:org.apache.jasper.JasperException: Can't find a method to write property 'databaseName' of type 'java.lang.String' in a bean of type 'database.operation.ShowRecordByPage'
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

...全文
58 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
runer 2011-03-05
java 是大小写相关的
回复
dandan880107 2011-03-05
那不是跟我写的没有区别?麻烦说下……
回复
runer 2011-03-05
兄弟,改成
public void setdatabaseName(String s)
{ databaseName=s.trim();
}
public String getdatabaseName()
{ return databaseName;
}

...

<jsp:setProperty name="look" property="databaseName" value="emp"/>
回复
dandan880107 2011-03-05
还是没有看出是哪里错了???麻烦高手指点下……
回复
runer 2011-03-05
public void setdatabaseName(String s)
{ databaseName=s.trim();
}
public String getdatabaseName()
{ return databaseName;
}

...

<jsp:setProperty name="look" property="databaseName" value="emp"/>
回复
dandan880107 2011-03-05
高手帮忙解决下,改了好久都没有找出为什么错了,急用……
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2011-03-05 09:02
社区公告
暂无公告