success.jsp
<%-- Created by IntelliJ IDEA. User: 13304 Date: 2021/7/31 Time: 17:43 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page import="com.example.GoldenManage.model.UserModel" %> <jsp:useBean id="userModel" class="com.example.GoldenManage.model.UserModel" scope="request"></jsp:useBean> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <title>用户注册成功</title> <link rel="stylesheet" href="css/style.css" /> <link rel="shortcut icon" type="image/x-icon" href="images/cugbIcon.ico"/> <body> <div class="register-container"> <h1>黄金矿工</h1> <div class="connect"> <p>welcome to cugb</p> </div> <%--onpaste是否运行粘贴;oncontextmenu 是否允许展开右键菜单;placeholder 输入提示;autocomplete是否允许浏览器自动补齐--%> <form action="" method="post" id="registerForm"> 恭喜您注册成功,您的注册信息如下,请牢记: <div> <input type="text" name="name" class="name" placeholder="您的用户名: ${userModel.username}" autocomplete="off" readonly="readonly"/> </div> <div> <input type="password" name="password" class="password" placeholder="您的密码: ${userModel.password}" oncontextmenu="return false" onpaste="return false" readonly="readonly" /> </div> <div> <input type="text" name="phone_number" class="phone_number" placeholder="您的手机号: ${userModel.phone}" autocomplete="off" id="number" readonly="readonly"/> </div> <div> <input type="email" name="email" class="email" placeholder="您的邮箱地址: ${userModel.email}" oncontextmenu="return false" onpaste="return false" readonly="readonly" /> </div> </form> <a href="login.jsp"> <button type="button" class="register-tis" style="width: 300px">返回登录</button> </a> </div> <script src="js/jquery.min.js"></script> <!--背景图片自动更换--> <script src="js/supersized.3.2.7.min.js"></script> <script src="js/supersized-init.js"></script> <!--表单验证--> <script src="js/jquery.validate.min.js?var1.14.0"></script> <script src="js/common.js"></script> </body> </html>
error.jsp
<%@ page import="java.util.ArrayList" %><%-- Created by IntelliJ IDEA. User: 13304 Date: 2021/7/31 Time: 17:44 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page import="java.util.ArrayList" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html> <head> <title>Title</title> </head> <body> <% ArrayList<String> list=(ArrayList<String>)request.getAttribute("error") ;%> <c:forEach items="${list}" var="item" varStatus="varIndex"> <c:if test="${varIndex.count%2==0 }"> <tr bgcolor=red> </c:if> <c:if test="${varIndex.count%2!=0 }"> <tr bgcolor=yellow> </c:if> <td>${item}</td> </tr> </c:forEach> </body> </html>
index.jsp
<%-- Created by IntelliJ IDEA. User: 13304 Date: 2021/7/31 Time: 16:46 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no"> <title>首页</title> <link rel="stylesheet" href="css/bootstrap.min.css"> <link rel="shortcut icon" type="image/x-icon" href="images/cugbIcon.ico" /> <link rel="stylesheet" href="css/index.css"> </head> <body> <!--描述:导航条部分:用于放置重要的页面导航------------------------------------- --> <nav class="navbar navbar-inverse navbar-fixed-top"> <div class="navbar-header"> <!-- 作者:1330465864@qq.com 时间:2016-04-09 描述:按钮绑定导航栏要显示的东西,屏幕缩小时 --> <!--导航栏与隐藏按钮绑定,屏幕缩小时导航栏隐藏--> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-info"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <div> <a href="##" class="navbar-brand"> Welcome to CUGB </a> </div> </div> <!--导航栏设置显示--> <div class="collapse navbar-collapse navbar-responsive-collapse" id="navbar-info"> <div> <ul class="nav navbar-nav navbar-left"> <li class="active"><a href="index.jsp"><span class="glyphicon glyphicon-home"></span> 首页</a></li> </ul> </div> <div> <ul class="nav navbar-nav navbar-right" style="margin-right: 10px;" > <li class="active"><a href="loginout.jsp"><span class="glyphicon glyphicon-globe"></span> 退出登录</a></li> </ul> </div> </div> </div> </nav> <div id="myCarousel" class="carousel slide"> <ol class="carousel-indicators"> <li data-target="#myCarousel" data-slide-to="0" class="active"></li> <li data-target="#myCarousel" data-slide-to="1"></li> <li data-target="#myCarousel" data-slide-to="2"></li> <li data-target="#myCarousel" data-slide-to="3"></li> <li data-target="#myCarousel" data-slide-to="4"></li> <li data-target="#myCarousel" data-slide-to="5"></li> </ol> <div class="carousel-inner"> <div class="item active" style="background:#223240"> <img src="images/slide1.jpg" alt="第一张" width="100%" height=""> </div> <div class="item" style="background:#F5E4DC;"> <img src="images/slide2.jpg" alt="第二张" width="100%" height=""> </div> <div class="item" style="background:#DE2A2D;"> <img src="images/slide3.jpg" alt="第三张" width="100%" height=""> </div> <div class="item" style="background:#DE2A2D;"> <img src="images/slide4.jpg" alt="第四张" width="100%" height=""> </div> <div class="item" style="background:#DE2A2D;"> <img src="images/slide5.jpg" alt="第五张" width="100%" height=""> </div> <div class="item" style="background:#DE2A2D;"> <img src="images/slide6.jpg" alt="第六张" width="100%" height=""> </div> </div> <!-- 作者:1330465864@qq.com 时间:2016-04-09 描述:轮播左右控制组建 --> <a href="#myCarousel" data-slide="prev" class="carousel-control left"> <span class="glyphicon glyphicon-chevron-left"></span> </a> <a href="#myCarousel" data-slide="next" class="carousel-control right"> <span class="glyphicon glyphicon-chevron-right"></span> </a> </div> <div class="container " id="timg"> <div class="row "> <div class="col-md-3 col-sm-6 col-xs-12 img_box" style="margin-top: 15px ; "> <a href="" class="thumbnail"> <img src="images/thumbnail1.jpg " /> </a> <div class="well well-lg "> <p align="center"> <b>按照地质类型</b> </p> <p style="color:gray; "> 您可以选择按照地质地区类型的方式查找该区域所有金矿说明,我们为您提供我们提供该区域金矿的产量,品位,等金矿参数以及已在该区域发表过的论文集。</p> </div> </div> <div class="col-md-3 col-sm-6 col-xs-12 img_box " style="margin-top: 15px ; "> <a href="map.html" class="thumbnail "> <img src="images/thumbnail2.jpg " /> </a> <div class="well well-lg "> <p align="center"> <b>按照行政区域</b> </p> <p style="color:gray; "> 您可以选择按照行政区域查找的方式,查找中华人民共和国33个行政区域(除上海市外)黄金矿产资源的数据,我们提供该区域金矿的产量,提交量等详细信息。</p> </div> </div> <div class="col-md-3 col-sm-6 col-xs-12 img_box " style="margin-top: 15px ; "> <a href=" " class="thumbnail "> <img src="images/thumbnail3.jpg " /> </a> <div class="well well-lg "> <p align="center"> <b>按照地质区域</b> </p> <p style="color:gray; "> 您可以选择按照地质区域查找的方式查找我国主要矿区东北北部砂金矿区,燕辽金矿区,山东金矿区,东南地区金矿区,秦岭-祁连山金矿区等重要矿区的信息。</p> </div> </div> <div class="col-md-3 col-sm-6 col-xs-12 img_box " style="margin-top: 15px ; "> <a href=" " class="thumbnail "> <img src="images/thumbnail4.jpg " /> </a> <div class="well well-lg "> <p align="center"> <b>按照开采技术</b> </p> <p style="color:gray; "> 您可以选择按照开采技术分类查找的方法如(矿体测伏规律,分支符合规律,地球化学叠加晕,大功率机电法,电磁技术等)查找采用该方法开采的所有矿区。</p> </div> </div> </div> </div> <!-- 作者:1330465864@qq.com 时间:2016-04-11 描述:第二行的四个元素 --> <div class="container" id="timg2"> <div class="row "> <div class="col-md-3 col-sm-6 col-xs-12 img_box" style="margin-top: 5px ; "> <a href=" " class="thumbnail "> <img src="images/thumbnail5.jpg " /> </a> <div class="well well-lg "> <p align="center"> <b>按照期刊选编</b> </p> <p style="color:gray; "> 您可以选择按照期刊选编查找的方式,查找我们为您收录的各大重要期刊及论文检索机构已发表的截止至今所有该期刊收录的论文,并且会持续更新该项内容。</p> </div> </div> <div class="col-md-3 col-sm-6 col-xs-12 img_box" style="margin-top: 5px ; "> <a href=" " class="thumbnail "> <img src="images/thumbnail6.jpg " /> </a> <div class="well well-lg "> <p align="center"> <b>按照矿石类别</b> </p> <p style="color:gray; "> 您可以选择按照金矿类别查找的方式,查找我们为您收录的包括自然金,金银矿,银金矿,自然银主要四种类别在内的金矿类别集,并且会持续更新该项内容。</p> </div> </div> <div class="col-md-3 col-sm-6 col-xs-12 img_box" style="margin-top: 5px ; "> <a href=" " class="thumbnail "> <img src="images/thumbnail7.jpg " /> </a> <div class="well well-lg "> <p align="center"> <b>按照矿床类型</b> </p> <p style="color:gray; "> 您可以选择按照矿床类型查找的方式,查找我们为您已分类的地球各个主要地质年代的多种类型金矿(如卡林型)的详细信息集合,并且会持续更新该项内容。</p> </div> </div> <div class="col-md-3 col-sm-6 col-xs-12 img_box" style="margin-top: 5px ; "> <a href=" " class="thumbnail "> <img src="images/thumbnail8.jpg " /> </a> <div class="well well-lg "> <p align="center"> <b>按照国际矿脉</b> </p> <p style="color:gray; "> 您可以选择按照国际矿脉查找的方式,查找我们为您收录的国际上一些比较著名的大型金矿,包括其详细开采信息和涉及论文集合,并且会持续更新该项内容。</p> </div> </div> </div> </div> </div> </div> <footer id="footer"> <div class="container" style="margin-top: 1px;"> <div class="row"> <div class="contact col-lg-1 col-sm-1 hidden-xs img_box"> <a href="" class="thumbnail"><img src="images/weixin.png" /> </a> </div> <div class="contact col-lg-1 col-sm-1 hidden-xs img_box"> <a href="" class="thumbnail"><img src="images/weixin.jpg" /> </a> </div> <div class="col-lg-8 col-sm-8 col-xs-12" style="margin-top: 25px;"> <p> <a href="http://www.cugb.edu.cn/index.action " style="color:lightblue; ">中国地质大学(北京) </a>|<a href="http://www.cnki.net/ " style="color: lightblue; "> 中国知网 </a> | <a href="http://www.mlr.gov.cn/ " style="color:lightblue; ">中华人民共和国国土资源部</a> </p> <p>中国地质大学(北京)资源数据库</p> </div> <div class="contact col-lg-1 col-sm-1 hidden-xs hidden-xs img_box"> <a href="" class="thumbnail"><img src="images/qq.png" /> </a> </div> <div class="contact col-lg-1 col-sm-1 hidden-xs img_box"> <a href="" class="thumbnail"><img src="images/qq.jpg" /> </a> </div> </div> </div> </footer> <script src="js/jquery.min.js "></script> <script src="js/bootstrap.min.js "></script> <script src="js/index.js "></script> </body> </html>
Lisenter代码清单
监听器主要用来处理服务器启动和关闭时候的监听操作:
package com.example.GoldenManage.listener; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.annotation.*; import java.time.LocalDate; import java.util.Date; @WebListener public class CountListener implements HttpSessionListener,ServletContextListener,HttpSessionAttributeListener { public CountListener() { } //监听application销毁事件--即服务器关闭 @Override public void contextDestroyed(ServletContextEvent sce) { System.out.println("application销毁, 服务停止,停止时间:"+ LocalDate.now()); } //监听application创建事件--即服务器开启 @Override public void contextInitialized(ServletContextEvent sce) { System.out.println("application创建,服务启动,启动时间:"+ LocalDate.now()); } }
Filter代码清单
过滤器主要为了完成请求的拦截,只有登录后才会绕过拦截:
package com.example.GoldenManage.filter; import javax.servlet.*; import javax.servlet.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.IOException; @WebFilter(filterName = "LoginFilter",urlPatterns= "*.jsp") public class LoginFilter implements Filter { public void init(FilterConfig config) throws ServletException { } public void destroy() { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException { HttpServletRequest requestServlet = (HttpServletRequest) request; HttpServletResponse responseServlet = (HttpServletResponse) response; HttpSession session=((HttpServletRequest) request).getSession(); String loginStatus=(String)session.getAttribute("loginStatus"); String url=requestServlet.getRequestURI(); //登录和注册页面无需跳转登录页面,否则会一直报重定向的错误 if(url.endsWith("login.jsp")||url.endsWith("register.jsp")){ chain.doFilter(request, response); return; } if(loginStatus==null || !loginStatus.equals("true")){ responseServlet.sendRedirect("login.jsp"); return; }else{ chain.doFilter(request, response); } } }