纯JSP分页代码之sqlserver2005/2008
上一篇分页文章,是用于mysql,稍微修改下,用于Sqlserver2005/2008,没有异常处理。没有考虑性能等。
现将代码贴出,以供初学者参考:
注:邀月使用环境Eclipse 3.4.2+Tomcat 6.18+Sqlserver2005 sp3调试成功。
页面pagelistDemo.jsp内容:
Code
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
//连接字符串
String url = "jdbc:sqlserver://" + Globals.Server
+ ";databaseName=" + Globals.DbName;
Class.forName(Globals.driverName).newInstance();
Connection connection = DriverManager.getConnection(url,
Globals.username, Globals.pwd);
Statement statement = connection.createStatement();
//每页显示记录数
int PageSize = 10;
int StartRow = 0; //开始显示记录的编号
int PageNo = 0;//需要显示的页数
int CounterStart = 0;//每页页码的初始值
int CounterEnd = 0;//显示页码的最大值
int RecordCount = 0;//总记录数;
int MaxPage = 0;//总页数
int PrevStart = 0;//前一页
int NextPage = 0;//下一页
int LastRec = 0;
int LastStartRecord = 0;//最后一页开始显示记录的编号
//获取需要显示的页数,由用户提交
if (request.getParameter("PageNo") == null) {&n
相关文档:
首先说说为什么要静态化。
对于现在的Web Application来说,动态页面是占有绝对高的地位的,正因为有了动态化,才有了现在Web的丰富多彩,但是如同所有别的事实一样,好处往往都是有代价的。
为了产生出动态的效果,每一次对页面的请求都会要求服务器对页面进行编译或者执行,这些操作都很消耗系统资源。如果这期间还有 ......
注意:jsp:useBean动作,用表单为Bean的属性赋值时,也就是jsp:setProperty动作直接收请求中表单的信息为使用的Bean的属性进行赋值,也就是说jsp:useBean和jsp:setProperty不能够出现在为这个Bean的属性赋值的form表单的页面上。
JSP的异常处理
<%@page errorPage="xxx.jsp"%> 指定本页面出现异常后要转到的页面
& ......
表结构:
CREATE TABLE `article` (
`id` int(10) unsigned ......
//运行图:
//连接字符串
String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
Class.forName(driverName).newInstance();
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
//每页显示记录数
int PageSize ......