JavaWeb增删改查以及从零到深的剖析分页以及cookie登录

这是关于一个分页慢慢使用的知识变多的项目,可能会有顺序错误,但是小问题,懒得理了。项目链接:链接:https://pan.baidu.com/s/1kbcrFSqMGgDBVAypri_vXw 密码:vxdb

我就直接把最终成果贴出来,想要研究,请自行查看代码。可能会有出错代码,反正也只是照着老师敲的,有问题很正常,不要再骂了。

第五个访问主页的路径

http://localhost:8080/request3/AllServlet/getAll

注意:第五个request5包,有可能出现路径不对,只有通过request3访问,因为直接复制前一份代码,出现这个不知道也不想解决的问题!!

<%@page import="java.util.Arrays"%>
<%@page import="com.liin.service.StudentService"%>
<%@page import="com.lilin.entity.StudentPage"%>
<%@page import="com.lilin.entity.Student"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<script type="text/javascript">
		window.onload = function() {
			var f = function seach(pageNo) {
				var id = document.getElementById("id").value;
				var name = document.getElementById("name").value;
				var minScore = document.getElementById("minScore").value;
				var maxScore = document.getElementById("maxScore").value;
				var pageSize = document.getElementById("pageSize").value;
				var url = "AllServlet/getAll?id=" + id + "&name=" + name
						+ "&minScore=" + minScore + "&maxScore=" + maxScore
						+ "&pageNo=" + pageNo + "&pageSize=" + pageSize;
				return url;
			}
			var pageNo = document.getElementById("pageNo").value;
			//查询
			var submit = document.getElementById("query");
			var skip = document.getElementById("skip");
			submit.onclick = function() {
				var url = f(1);
				this.href = url;
			};
			//跳转
			skip.onclick = function() {
				var pageNo = document.getElementById("pageNo").value;
				var url = f(pageNo);
				this.href = url;
			}
			//第一页
			var firstPage = document.getElementById("firstPage");
			firstPage.onclick = function() {
				var url = f(1);
				this.href = url;
			}
			//末页
			var lastPage = document.getElementById("lastPage");
			lastPage.onclick = function() {
				var maxPageNo = document.getElementById("maxPageNo").innerText;
				if (pageNo == maxPageNo) {
					return false;
				}
				var url = f(maxPageNo);
				this.href = url;
			}
			//下一页
			var nextPage = document.getElementById("nextPage");
			nextPage.onclick = function() {
				var maxPageNo = document.getElementById("maxPageNo").innerText;
				if (pageNo == maxPageNo) {
					return false;
				}
				var n = parseInt(pageNo);
				var url = f(n + 1);
				this.href = url;
			}
			//上一页
			console.log(pageNo);
			var prevPage = document.getElementById("prevPage");
			prevPage.onclick = function() {
				if (pageNo == 1) {
					return false;
				}
				var n = parseInt(pageNo);
				var url = f(n - 1);
				this.href = url;
			}
			
			var sp=	${sp.pageSize};
			var pageSize=document.getElementById("pageSize");
			var index = pageSize.selectedIndex;
			var placeValue = pageSize.options[index].text;
			for(var i=0;i<pageSize.options.length;i++){
				var value= pageSize.options[i].text;
				console.log(value);
				if(sp==value){
					pageSize.options[i].selected=true;
				}
			}
		}
	</script>
<style type="text/css">
.liulan{
	width: 400px;
	height: 400px;
	border: 1px solid #000;
	float: right;
}
.left {
	float: left;
}
	<c:choose>
	<c:when test="${empty sessionScope.users }">
		 #login {
		 	display:block;
		}
		#logout {
			display: none;
		}
	</c:when>
	<c:otherwise>
		 #login { 
		 	display:none;
		}
		
		#logout {
			display: block;
		}
	</c:otherwise>
	</c:choose>
</style>
	<div class="left">
		<h1>图书信息</h1>
		<a href="${empty users?"AllServlet/getAll":"update.jsp"}">添加信息</a>
		<a href="user.jsp" id="login">登录</a>
		${sessionScope.users!=null?sessionScope.users:""}
		<!-- 这里如果删除,会每次清空 ,千万不要remove-->
		<c:if test="${not empty sessionScope.users}">
       		 <a href="AllServlet/doLogoutServlet" id="logout" title="注销">注销</a>
   		 </c:if>
			学号:<input type="text" name="id" id="id" value="${sp.id==0?"":sp.id }"> 
			学生姓名: <input type="text" name="name" id="name" placeholder="请输入关键字" value="${sp.name }"> 
			成绩:<input type="text" name="minScore" id="minScore" size="4" value="${ sp.minScore}">-
		<input type="text" name="maxScore" id="maxScore" size="4" value="${ sp.maxScore}"> 
		<a href="AllServlet/getAll"id="query">查询</a> <br>
		 <a href="#" id="firstPage">首页</a> 
		 <a href="#" id="prevPage">上一页</a> <a href="#" id="nextPage">下一页</a> 
		 <a	href="#" id="lastPage">末页</a> &nbsp;共${sp.pageNo }/
		 <span id="maxPageNo">${sp.maxPageNo }</span> 页&nbsp;&nbsp;
		  每页<select name="pageSize" id="pageSize">
			<option value="10">10</option>
			<option value="20">20</option>
			<option value="30">30</option>
			<option value="40">40</option>
			<option value="50">50</option>
		</select>条 &nbsp;&nbsp;跳至 <input type="text" name="pageNo" id="pageNo" size="1"
			value="${sp.pageNo }"> <a href="" id="skip">跳转</a>
		<table border="1" cellspacing="0" cellpadding="0" width="880px">
			<tr>
				<th>学号</th>
				<th>学生姓名</th>
				<th>性别</th>
				<th>年龄</th>
				<th>成绩</th>
				<th>操作</th>
			</tr>
			<c:forEach var="s" items="${requestScope.sp.students }">
				<tr>
					<td>${s.id }</td>
					<td>${s.name }</td>
					<td>${s.sex }</td>
					<td>${s.age }</td>
					<td>${s.socre }</td>
					<td><a href="AllServlet/deleteSudent?id=${s.id }">删除</a>&nbsp;
						<a href="AllServlet/updateStudent?id=${s.id }">修改</a> 
						<a href="AllServlet/listStudent?id=${s.id }">详情</a></td>
				</tr>
			</c:forEach>
		</table>
	</div>
	<div class="liulan">
		<h3>浏览量排行榜</h3>
		<ol>
			<li><a href="./AllServlet/listStudent?id=${fn:split(cookie.historypro1.value,'-')[1] }">${fn:split(cookie.historypro1.value,'-')[0] }</a></li>
			<li><a href="./AllServlet/listStudent?id=${fn:split(cookie.historypro2.value,'-')[1] }">${fn:split(cookie.historypro2.value,'-')[0] }</a></li>
			<li><a href="./AllServlet/listStudent?id=${fn:split(cookie.historypro3.value,'-')[1] }">${fn:split(cookie.historypro3.value,'-')[0] }</a></li>
			<li><a href="./AllServlet/listStudent?id=${fn:split(cookie.historypro4.value,'-')[1] }">${fn:split(cookie.historypro4.value,'-')[0] }</a></li>
			<li><a href="./AllServlet/listStudent?id=${fn:split(cookie.historypro5.value,'-')[1] }">${fn:split(cookie.historypro5.value,'-')[0] }</a></li>
		</ol>
		
	</div>
</body>
</html>

代码太多,还有太晚了,不贴了,反正全部代码都在百度云里,想要自己下,数据库的密码记到修改,还有就是我没有使用xml配置,直接使用注解配置,有问题请百度!

package com.lilin.util;

import java.sql.Connection;
import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class JDBCUtils {
	
	private static ComboPooledDataSource ds = new ComboPooledDataSource();
	public static final QueryRunner qr =new QueryRunner(ds);
	
	static {
		try {
			ds.setJdbcUrl("jdbc:mysql://localhost:3306/sys?useUnicode=true&characterEncoding=utf-8&useSSL=false");
			ds.setDriverClass("com.mysql.jdbc.Driver");
			ds.setUser("root");
			ds.setPassword("123");
		}catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	public static Connection getConnection() {
		try {
			return ds.getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
	
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hikktn

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值