MyException - 我的异常网
当前位置:我的异常网» Java Web开发 » 分页有关问题

分页有关问题

www.MyException.Cn  网友分享于:2013-12-31  浏览:4次
分页问题
写个分页的代码
要求每页显示3张图片.jsp页面怎么写啊
我是把图片路径存到一个list里面,在jsp页面怎么调用呢

------解决方案--------------------
使用struts控件struts-html.tld
<logic:iterate id= "bbsTopicForm " name= "bbsTopicList " type= "gov.controller.bbs.BbsTopicForm " indexId= "indexId " offset= " <%=String.valueOf(Integer.parseInt(offset)*length)%> " length= " <%=String.valueOf(length)%> ">
<html:img ....>
</logic>
//说明:length是每页显示记录数;offset为当前页码数-1(从1开始)
标签的具体属性用法请参考http://struts.apache.org/网站上详细介绍
------解决方案--------------------

<%@page import= "java.sql.* "%>
<%@page contentType= "text/html;charset=gb2312 "%>
<html>
<head>
<link href= "css/main.css " rel= "stylesheet " type= "text/css ">
<link href= "css/text.css " rel= "stylesheet " type= "text/css ">
<title> 例子 </title>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 "> <style type= "text/css ">
<!--
body {
margin-top: 5px;
}
-->
</style> </head>
<body>
<%
int intPageSize = 20; //一页显示的记录数
int intRowCount ; //记录总数
int intPageCount ; //总页数
int intPage ; //待显示页码
java.lang.String strPage;
int i;
//取得待显示页码
strPage = request.getParameter( "page ");

Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();
String url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=hengan ";
//pubs为你的数据库的
String user= "sa ";
String password= "1234 ";
Connection con=DriverManager.getConnection(url,user,password);
Statement stmt=con.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
String querystring= "select * from test " ;
ResultSet rs = stmt.executeQuery(querystring);



if(strPage==null){//表明在QueryString中没有page这一个参数,此时显示第一页数据
intPage = 1;
}
else{//将字符串转换成整型
intPage = java.lang.Integer.parseInt(strPage);
if(intPage <1) intPage = 1;
}
rs.last();
intRowCount = rs.getRow();
//记算总页数
intPageCount = (intRowCount+intPageSize-1) / intPageSize;
//调整待显示的页码
if(intPage> intPageCount) intPage = intPageCount;
if(intPageCount> 0){
//将记录指针定位到待显示页的第一条记录上
rs.absolute((intPage-1) * intPageSize + 1);
//显示数据

%>
<table width= "98% " border= "0 " cellpadding= "2 " cellspacing= "1 " class= "TableBody " align= "center ">
<tr align= "center "bgcolor= "#9DCEFF " class= "TableHeader ">
<td> 1 </td>
<td> 2 </td>
<td> 3 </td>
<td> 编辑 </td>
</tr>
<%
i = 0;
while(i <intPageSize && !rs.isAfterLast()){%>
<tr bgcolor= "#ffffff ">
<td> <a href= "dysGuarantee.jsp?ID= <%=rs.getString(1)%> "> <%= rs.getString(2)%> </a> </td>
<td> <%= rs.getString( "Bbxr ")%> </td>
<td> <%= rs.getString( "Company ")%> </td>

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有