分页实现以及访问量的实现
来源:互联网 发布:智多星软件多少钱 编辑:程序博客网 时间:2024/06/10 01:15
访问首页
内置很多子页 访问子页也增加访问量以及子页的访问量 子页中或许会碰到下一页 上一页 首页 尾页 转到选定页 详细方法请看如下代码
首页
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
if (application.getAttribute("count") == null) {
application.setAttribute("count", new Integer(1));
}
Integer count = (Integer) application.getAttribute("count");
application.setAttribute("count", new Integer(count.intValue() + 1));
%>
<html>
<head>
<title>页面被访问数统计</title>
</head>
<body bgcolor="#ffffff">
<form action="fwl.jsp">
<!--输出访问次数 -->
<h1> 此页面访问量
: <%=count%> 次
</h1>
<a href="tushu.jsp">图书</a>
<%
Object count1=application.getAttribute("count1");
if(count1==null){%>
<%=0%>
<%}else{%>
<%=count1 %>
<%}%><br/>
<a href="bijiben.jsp">笔记本</a>
<%
Object count2=application.getAttribute("count2");
if(count2==null){%>
<%=0%>
<%}else{%>
<%=count2 %>
<%}%>
</form>
</body>
</html>
子页一
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="java.sql.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<title></title>
<body>
<%! int record = 2;
int total = 0;
%>
<%
Connection conn;
Statement stmt;
String url = "jdbc:mysql://localhost:3306/3g";
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url, "root", "");
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
String sql="select * from users order by id";
ResultSet rs = stmt.executeQuery(sql);
rs.last();
int ototal = rs.getRow();
if(ototal % record == 0){
total=ototal / record;
}else{
total=ototal / record +1;
}
int current = 1;
%>
<%
//获取指定页面
String appoint = request.getParameter("current");
if (appoint == null){
appoint = "1";
}
//类型转换
try{
current = Integer.parseInt(appoint);
}
catch (NumberFormatException ex){
current = 1;
}
if(current <=1){
current = 1;
}
else if(current >= total){
current = total;
}
int posion = (current -1 ) * record + 1;
rs.absolute(posion);
String cou=request.getParameter("flag");
if(cou==null){
if (application.getAttribute("count1") == null) {
application.setAttribute("count1", new Integer(0));
}
Integer count1 = (Integer) application.getAttribute("count1");
application.setAttribute("count1", count1+1);
}
%>
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<th>商品号</th>
<th>商品名称</th>
<th>详细信息</th>
</tr>
<%
int i =0;
while(i<record && !rs.isAfterLast()){
%>
<tr>
<td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
</tr>
<%rs.next();i++;}%>
</table>
<table width="700">
<tr>
<td>
<%if(current < total){%>
<a href="tushu.jsp?current=<%=current+1%>&flag=1">下一页</a>
<%}%>
</td>
<td><%if(current > 1){%>
<a href="tushu.jsp?current=<%=current-1%>&flag=1">上一页</a>
<%}%>
</td>
<td> 共<%=total%>页 </td>
<td> 第<%=current%>页 </td>
<td> <a href="tushu.jsp?current=1&flag=1">首页</a> </td>
<td> <a href="tushu.jsp?current=<%=total%>&flag=1">尾页</a> </td>
<td></td>
<td>
</td>
</tr>
</table>
<%
conn.close();
}catch (ClassNotFoundException e1)
{out.print(e1.getMessage());
}catch(SQLException e2)
{ out.print(e2.getMessage());}
%>
</body>
</html>
子页二
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'bijiben.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<h1>笔记本</h1>
<%
if (application.getAttribute("count2") == null) {
application.setAttribute("count2", new Integer(0));
}
Integer count2 = (Integer) application.getAttribute("count2");
application.setAttribute("count2", count2+1);
%>
</body>
</html>
- 分页实现以及访问量的实现
- 前端分页功能的实现以及原理
- GridView分页的实现以及自定义分页样式功能实例
- 简单的javaBean实现访问量统计
- 静态HTML页面的访问量统计实现
- java实现页面访问量统计的实例
- Servlet 实现访问量的统计小案例
- java jsp实现网站访问量的统计
- 利用ServletContext实现页面访问量的统计
- 【PHP】简单的网站访问量计数器实现
- 网站访问量统计实现.
- php实现网站访问量
- Asp.net实现通用以及高效的分页方法
- Repeater进行模板设计以及实现数据的分页显示
- DBCP与C3P0连接池以及基本分页的实现
- js 实现统计网站访问量
- java 实现IP访问量控制
- java 实现IP访问量控制
- JSP中九大隐式对象
- 二分图的最小点覆盖跟最小点权覆盖
- AR
- Asp.net控制TextBox只能输入数字
- ASP.NET中Server.MapPath() 和Request.MapPath()使用
- 分页实现以及访问量的实现
- 黑马程序员:我的黑马预习课程第一讲:数组
- 了解dt.jar
- 动态网页与静态网页各有各的特点
- 上百部BBC经典纪录片在线欣赏
- Xcode 4.2 中的Automatic Reference Counting (ARC)
- jsp实现记录访问次数实例
- sicily 1194
- Blogger Favicon - 面对上载后不呈现和not a square image问题