易截截图软件、单文件、免安装、纯绿色、仅160KB

JSP分页1

自己分页,下一篇会介绍使用diasplaytag组件。
使用mysql5, 有个数据表user,字段有id, username, password。
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>分页测试</title>
</head>
<%
String driver = "com.mysql.jdbc.Driver";
String username = "root";
String password = "leng";
String url = "jdbc:mysql://localhost/test";
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
Class.forName(driver);
conn = DriverManager.getConnection(url, username, password);
stmt = conn.createStatement();
String sql = "select * from user order by id asc";
rs = stmt.executeQuery(sql);
%>
<%
int countRecord = 0; //总记录数
int pageSize = 4; // 每页记录数
int countPage = 0 ; // 总页数
int dipage = 1; // 当前页码,默认从1开始
String pages = request.getParameter("page");
if(pages == null ){
pages = "1";
}
dipage = Integer.parseInt(pages);

rs.last();
countRecord = rs.getRow();
if(countRecord % pageSize == 0){
countPage = countRecord / pageSize;
} else {
countPage = countRecord / pageSize + 1;
}

if((dipage-1)*pageSize == 0){
// 第一页
rs.beforeFirst();
} else {
rs.absolute((dipage-1)*pageSize);
}

%>
<body>
<center>
<h3>分页测试</h3>
<table border="1">
<tr>
<th width="100">id</th>
<th width="300">用户名</th>
<th width="300">密码</th>
</tr>

<%
// 控制每页显示数
int i = 0;
while(rs.next()){
%>
<tr>
<td><%=rs.getInt("id") %></td>
&l


相关文档:

Jsp 连接 mySQL、Oracle 数据库备忘

Jsp 连接 mySQL、Oracle 数据库备忘
2009-12-15 16:47
Jsp 环境目前最流行的是 Tomcat5.0。Tomcat5.0 自己包含一个 Web 服务器,如果是测试,就没必要把 Tomcat 与 IIS 或 Apache 集成起来。在 Tomcat 自带的 Web 服务器下可以进行 Jsp 测试。
    安装 Tomcat5.0 前需要安装 JDK(如果是 Windows server ......

在JSP中配置FCKeditor 2.6.4

1.FCKeditor 介绍
FCKeditor 这个开源的HTML 文本编辑器可以让web 程序拥有如MS Word 这样强大的编辑功能,.FCKeditor 支持当前流行的浏览器。
2.准备工作:
环境:winddows XP、tomcat6.0、JDK1.6
下载:
1):FCKeditor_2.6.4.zip
地址:http://nchc.dl.sourceforge.net/sourceforge/fckeditor/FCKeditor_2.6.4.zip ......

Jsp连接MSSQL2000的两种方法


Jsp连接MSSQL2000的两种方法
最近在学习JSPWeb(Tomcat服务器)应用开发和基于Weblogic和Myelcipse的JEE5的开发,在学习过程中涉及到连接SQL 2000 数据库时,由于软件环境的差异性和一些版本问题,花了好大功夫才连上,所以在此作个总结,希望能给大家一些帮助,不要在基本的东西上花费太多的时间。
方法一:利用SQL Se ......

JSP自定义标签(Tag)

实现JSP自定义标签的一种方法:
1.写一个类继承TagSupport或其他Tag的实现类。
public class AllTag extends TagSupport {

@Override
public int doStartTag() throws JspException {
JspWriter out = pageContext.getOut();
try {
out.append("Hello World.");
} catch (IOException e) {
e.pri ......

jsp页面乱码问题

分两种:
Get方式传递数据解决办法:
<%
String username = request.getParameter("username");
byte[] bytes = username.getBytes("iso-8859-1");
String result = new String(bytes, "gb2312");
out.print(result);
%>
Post方式解决办法:request.setCharacterEncoding("gb2312");
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号