用javabean分页显示从数据库中查找的信息报错
page_sep.jsp:
<%@ page contentType="text/html; charset=gb2312"%>
<%@ page import="java.util.Vector" %>
<%@ page import="java.lang.*" %>
<%@ page import="wu.bean.BeanArticlePage" %>
<%@ page import="wu.bean.article" %>
<jsp:useBean id="page_sep" class=wu.bean.BeanArticlePage scope="session"></jsp:useBean>
<%
int intPageSize=4;//每页显示的记录数
int currPageBegin=0;//起始记录的索引
int intPageConut=0;//总页数
int intPage=0;//待显示页码
String strPage=null;//用户请求页码
%>
<%
article art=new article();
Vector<article> vector=new Vector<article>();
vector=page_sep.getResultSet();
strPage=request.getParameter("pagenumber");//pagenumber
if(strPage==null){
intPage=1;
}else{
intPage=Integer.parseInt(strPage);
if(intPage<1)
intPage=1;
}
//
intPageConut=(vector.size()+intPageSize-1)/intPageSize;
//调整带显示的页码
if(intPage>intPageConut)
intPage=intPageConut;
//计算每一页的起始记录索引
currPageBegin=intPage*intPageSize-intPageSize;
%>
<table align=center border=1 cellspacing=0 width=90%>
<tr>
<td align=center>作者</td>
<td align=center>标题</td>
<td align=center>类容</td>
</tr>
<%
for(int i=currPageBegin;i<intPage*intPageSize&&i<vector.size();i++)
{
art=(article)vector.elementAt(i);
%>
<tr bgcolor="#f0ffff">
<td align=center><font size=2><%=art.getUsername() %></font></td>
<td align=center><font size=2><%=art.getTitle() %></font></td>
<td align=center><font size=2><%=art.getContent() %></font></td>
</tr>
<%
}
%>
</table>
BeanArticlePage.java
:
package wu.bean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import wu.JDBC.ContantFinal;
import wu.JDBC.LoginAccess;
import wu.JDBC.SqlServerConn;
public class BeanArticlePage {
public Vector<article> getResultSet(){
LoginAccess la=new LoginAccess(new SqlServerConn());//SQLServer数据库的链接
try {
ResultSet rs=la.SetAll(new ContantFinal().artcle);//从表artcle中查找所有信息
Vector<article> vector=new Vector<article>();
while(rs.next()){
article ar=new article();
ar.setArticleID(rs.getInt("articleID"));
ar.setUsername(rs.getString("username"));
ar.setTitle(rs.getString("title"));
ar.setContent(rs.getString("content"));
vector.addElement(ar);
System.out.println("success");
}
System.out.println("success");
return vector;
} catch (SQLException e) {
e.printStackTrace();
la.Close();
}
return null;
}
}
article.java
package wu.bean;
public class article {
public int articleID=0;
public String username=null;
public String title=null;
public String content=null;
public int getArticleID() {
return articleID;
}
public void setArticleID(int articleID) {
this.articleID = articleID;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
[解决办法]
test.jsp(6,34),这个jsp的第六行第34列需要引号,你的没有引号所以报这个错误了,仔细检查检查。