首页 > 其他分享 >第三章. 业务功能开发--登录验证(使用拦截器)

第三章. 业务功能开发--登录验证(使用拦截器)

时间:2022-11-23 13:12:47浏览次数:39  
标签:模态 拦截器 第三章 登录 -- import 页面

第三章. 业务功能开发--登录验证(使用拦截器)

需求

登录验证.
	用户访问任何业务资源,都需要进行登录验证.	
	*只有登录成功的用户才能访问业务资源
	*没有登录成功的用户访问业务资源,跳转到登录页面

结构:

1.拦截器

  1. 定义一个拦截器:

    package com.bjpowernode.crm.settings.web.interceptor;
    
    import com.bjpowernode.crm.commons.contants.Contants;
    import com.bjpowernode.crm.settings.domain.User;
    import org.springframework.web.servlet.HandlerInterceptor;
    import org.springframework.web.servlet.ModelAndView;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    
    public class LoginInterceptor implements HandlerInterceptor {
        @Override
        public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
            //如果用户没有登录成功,则跳转到登录页面
            HttpSession session=httpServletRequest.getSession();
            User user=(User) session.getAttribute(Contants.SESSION_USER);
            if(user==null){
                httpServletResponse.sendRedirect(httpServletRequest.getContextPath());//重定向时,url必须加项目的名称
                return false;
            }
            return true;
        }
    
        @Override
        public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
    
        }
    
        @Override
        public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
    
        }
    }
    
  2. 注册拦截器

    注意哪些应该拦截,哪些不应该拦截。拦截成功之后往哪里跳转。

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:p="http://www.springframework.org/schema/p"
           xmlns:util="http://www.springframework.org/schema/util"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xmlns:mvc="http://www.springframework.org/schema/mvc"
           xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/util
    http://www.springframework.org/schema/util/spring-util.xsd">
        <!-- dispatcherServlet截获所有URL请求 -->
        <mvc:default-servlet-handler />
        <!-- spring mvc 扫描包下的controller -->
        <context:component-scan base-package="com.bjpowernode.crm.web.controller"/>
        <context:component-scan base-package="com.bjpowernode.crm.settings.web.controller"/>
        <context:component-scan base-package="com.bjpowernode.crm.workbench.web.controller"/>
        <!-- 配置注解驱动 -->
        <mvc:annotation-driven/>
        <!-- 配置视图解析器 -->
        <bean id="viewResolver"
              class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/pages/"/>
            <property name="suffix" value=".jsp"/>
        </bean>
    
        <mvc:interceptors>
            <mvc:interceptor>
                <!--配置拦截的请求-->
                <mvc:mapping path="/settings/**"/>
                <mvc:mapping path="/workbench/**"/>
                <!--配置排除拦截的请求(优先级高)-->
                <mvc:exclude-mapping path="/settings/qx/user/toLogin.do"/>
                <mvc:exclude-mapping path="/settings/qx/user/login.do"/>
                <!--拦截器类-->
                <bean class="com.bjpowernode.crm.settings.web.interceptor.LoginInterceptor"/>
            </mvc:interceptor>
        </mvc:interceptors>
    
        <!-- 配置文件上传解析器 id:必须是multipartResolver-->
        <!--<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
            <property name="maxUploadSize" value="#{1024*1024*80}"/>
            <property name="defaultEncoding" value="utf-8"/>
        </bean>-->
    </beans>
    

2. 总结:拦截器,页面切割技术,模态窗口

1,登录验证:

   1)过滤器:
     a)implements Filter{
         --init
	 --doFilter
	 --destroy
       }
     b)配置过滤器:web.xml
   2)拦截器:
     a)提供拦截器类:implements HandlerInterceptor{
			  --pre
			  --post
			  --after
                     }
     b)配置拦截器:springmvc.xml
    
2,页面切割技术:
  1)<frameset>和<frame>:
    <frameset>:用来切割页面.
                <frameset cols="20%,60%,20%" rows="10%,80%,10%">
    <frame>:显示页面.
                <frame src="url">

		<frameset cols="20%,60%,20%">
			<frame src="url1" name="f1">
			<frame src="url2" name="f2">
			<frame src="url3" name="f3">
		</frameset>

             每一个<frame>标签就是一个独立的浏览器窗口。

	     <a href="url" target="f3">test</a>
  2)<div>和<iframe>:
    <div>:切割页面。
            <div style="height:10%;width=20%">
   <iframe>:显示页面。
            <div style="height:10%;width=20%">
		<iframe href="url">
	    </div>
3,创建市场活动:
  
  模态窗口:模拟的窗口,本质上是<div>,通过设置z-index大小来实现的;
            初始时,z-index初始参数是<0,所以不显示;
	    需要显示时,z-index值设置成>0即可。

	    bootstrap来控制z-index的大小。
  控制模态窗口的显示与隐藏:
            1)方式一:通过标签的属性data-toggle="modal" data-target="模态窗口的id"
	    2)方式二:通过js函数控制:
	              选择器(选中div).modal("show");//显示选中的模态窗口
		      选择器(选中div).modal("hide");//关闭选中的模态窗口
            3)方式三:通过标签的属性data-dismiss=""
		      点击添加了data-dismiss=""属性的标签,自动关闭该标签所在的模态窗口。
  模态窗口的意义:
            window.open("url","_blank");
	    模态窗口本质上就是原来页面中的一个<div>,只有一个页面;所有的操作都是在同一个页面中完成。

标签:模态,拦截器,第三章,登录,--,import,页面
From: https://www.cnblogs.com/atao-BigData/p/16917938.html

相关文章

  • 一文讲透CabloyJS全栈框架的来龙去脉
    本文受众咱们做软件开发,就好比是建造一幢幢房屋,一座座桥梁,既可以是北方宫殿的巍峨,也可以有南方庭院的雅致,更可以是横跨群山的峻险与孤悬。那么,不同的语言、不同的框架也都......
  • Educational Codeforces Round 36 (Rated for Div. 2) E Physical Education Lessons
    PhysicalEducationLessons珂朵莉树模板#include<iostream>#include<cstdio>#include<set>usingnamespacestd;#defineItset<ran>::iteratorstructran{......
  • Servlet_执行原理、生命周期方法
    Servlet_执行原理  执行原理:当服务器接收到客户端浏览器的请求后,会解析请求URL路径,获取访问的Servlet的资源路径查找web.xml文件,是否有对应的<url-pattern>......
  • 带着问题读论文
    带着问题读论文:1、这篇论文解决了什么问题,动机是什么2、神经网络结构是如何去构建的3、模型训练的输入是什么,输出是什么,训练集是什么,如何进行训练,有监督还是无监督4、......
  • Codeforces Round #449 (Div. 1) C Willem, Chtholly and Seniorious
    Willem,ChthollyandSeniorious珂朵莉树慕名而来操作\(3\)直接排序是我没想到的,因为随机数据所以才能过吧\(split\)操作中忘了开\(longlong\),\(wa3\)#include<......
  • 题解 LGP7489【「Stoi2031」手写的从前】
    problem令\(f_0(S)=\dfrac{\sigma(S)}{\pi(S)}\),\(f_k(S)=\sum\limits_{T\subseteqS}f_{k-1}(T)\)。其中\(\sigma(S)=\sum\limits_{x\inS}x\)为\(S\)中所有元素......
  • win32开发(定时器)
      要说除了鼠标、键盘消息之外,还有什么消息最重要。我想大概是就是定时器了。这定时器可长可短,如果是短定时器的话,那么就可以形成动画,记录成视频。如果是长定时器的话,那......
  • win32开发(图形绘制)
      在win32上面绘制图形其实是比较简单的。要想进行图形绘制,关键是找到设备上下文。就我目前所知道的,获得设备上下文主要有这么几种方式:一、根据BeginPaint获得设备上下......
  • win32开发(按键消息)
      对于一个应用来说,按键和鼠标都是基本的消息。当然,win32也需要独立处理按键消息和鼠标消息。今天,我们就讨论一下按键消息。一般认为,当键盘上一个key按下去之后,os会给ap......
  • python编程(改进的线程同步方式)
      在实际代码开发中,gui的代码并不好写。因为不管是mvc、还是mvp都有一定的局限性。那么,这个时候,我就在想,是不是可以用mvp+reactor的方法进行gui的改进操作呢?首先app编写......