需求征集系统第四天

今天设计了首页,设置了过滤器


<%--
  Created by IntelliJ IDEA.
  User: 张志伟
  Date: 2020/10/15
  Time: 16:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>首页</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="${pageContext.request.contextPath }/bootstrap/css/bootstrap.min.css">
  <script src="${pageContext.request.contextPath }/bootstrap/js/jquery-3.5.1.min.js"></script>
  <script src="${pageContext.request.contextPath }/bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<!--导航栏-->
<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">重大需求征集系统 <small>V1.0</small></a>
    </div>

    <ul class="nav navbar-nav navbar-right">
      <li><a href="#"> <span class="text-danger">${sessionScope.user.username}</span> 您好</a></li>
      <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">个人中心 <span class="caret"></span></a>
        <ul class="dropdown-menu">
          <li><a href="#">我的信息</a></li>
          <li role="separator" class="divider"></li>
          <li><a href="#">修改密码</a></li>
          <li role="separator" class="divider"></li>
          <li><a href="${pageContext.request.contextPath}/exitServlet">退出登录</a></li>
          <li role="separator" class="divider"></li>
        </ul>
      </li>
    </ul>
  </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>
<!--导航栏-->

<!--页面中心内容-->
<div class="container-fluid">

  <div class="row">
    <!--左半区-->
    <div class="col-sm-2">

      <!--菜单组件-->
      <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">

        <div class="panel panel-default">
          <div class="panel-heading" role="tab" id="headingOne">
            <h4 class="panel-title">
              <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                用户管理
              </a>
            </h4>
          </div>
          <div id="collapseOne" class="panel-collapse collapse " role="tabpanel" aria-labelledby="headingOne">
            <div class="panel-body">
              <ul class="list-group">
                <a class="list-group-item" href="${pageContext.request.contextPath}/usermangeServlet">用户管理</a>
                <a class="list-group-item"href="${pageContext.request.contextPath}/rolemangeServlet">权限管理</a>
              </ul>
            </div>
          </div>
        </div>

        <div class="panel panel-default">
          <div class="panel-heading" role="tab" id="headingTwo">
            <h4 class="panel-title">
              <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="true" aria-controls="collapseOne">
                需求管理
              </a>
            </h4>
          </div>
          <div id="collapseTwo" class="panel-collapse collapse " role="tabpanel" aria-labelledby="headingTwo">
            <div class="panel-body">
              <ul class="list-group">
                <a class="list-group-item" href="">需求征集</a>
                <a class="list-group-item" href="">需求管理</a>
              </ul>
            </div>
          </div>
        </div>

        <div class="panel panel-default">
          <div class="panel-heading" role="tab" id="headingThree">
            <h4 class="panel-title">
              <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="true" aria-controls="collapseOne">
                审核
              </a>
            </h4>
          </div>
          <div id="collapseThree" class="panel-collapse collapse " role="tabpanel" aria-labelledby="headingThree">
            <div class="panel-body">
              <ul class="list-group">
                <a class="list-group-item" href="">形式审核</a>
                <a class="list-group-item" href="">部门审核</a>
              </ul>
            </div>
          </div>
        </div>

        <div class="panel panel-default">
          <div class="panel-heading" role="tab" id="headingFour">
            <h4 class="panel-title">
              <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseFour" aria-expanded="true" aria-controls="collapseOne">
                统计查询
              </a>
            </h4>
          </div>
          <div id="collapseFour" class="panel-collapse collapse " role="tabpanel" aria-labelledby="headingFour">
            <div class="panel-body">
              <ul class="list-group">
                <a class="list-group-item" href="">分类检索</a>
                <a class="list-group-item" href="">综合检索</a>
                <a class="list-group-item" href="">统计图表</a>
              </ul>
            </div>
          </div>
        </div>

      </div>

    </div>
    <!--左半区-->

    <!--中间部分-->
    <div id="content">
      <!--页面中心内容-->
      <div class="col-sm-10">
        <!--巨幕-->
        <div class="jumbotron">
          <h1>欢迎使用需求征集系统</h1>
          <p>
            为了充分利用京津科技资源,破解我省产业转型升级、绿色崛起所面临的重大技术难题,按照厅领导指示,现面向重点产业、重点领域、
            重点企业(单位)征集产业或领域关键技术难题,构建我省重大技术需求数据库,特制定本工作方案。
          </p>
        </div>

      </div>
    </div>
    <!--中间部分-->

  </div>

</div>
<!--页面中心内容-->



</body>
</html>

package web.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@WebFilter( "/*")
public class LoginFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        //System.out.println(req);

        //0.强制转换
        HttpServletRequest request = (HttpServletRequest) req;

        //1.获取资源请求路径
        String uri = request.getRequestURI();
        //2.判断是否包含登录相关资源路径,要注意排除掉 css/js/图片/验证码等资源
        if(uri.contains("/login.jsp") || uri.contains("/loginServlet") ||uri.contains("/register.jsp") || uri.contains("/registerServlet")|| uri.contains("/bootstrap/")|| uri.contains("/checkCodeServlet")  ){
            //包含,用户就是想登录。放行
            chain.doFilter(req, resp);
        }else{
            //不包含,需要验证用户是否登录
            //3.从获取session中获取user
            Object user = request.getSession().getAttribute("user");
            if(user != null){
                //登录了。放行
                chain.doFilter(req, resp);
            }else{
                //没有登录。跳转登录页面

                request.setAttribute("login_msg","您尚未登录,请登录");
                request.getRequestDispatcher("/login.jsp").forward(request,resp);
            }
        }
    }

    public void init(FilterConfig config) throws ServletException {

    }

}

posted @ 2020-10-22 22:37  夜月薇凉映银弩  阅读(61)  评论(0编辑  收藏  举报