springmvc拦截器的配置、使用:
1.自定义拦截器,实现HandlerInterceptor接口。

package com.bybo.aca.web.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView; public class Login implements HandlerInterceptor { @Override
public void afterCompletion(HttpServletRequest httpRequest,
HttpServletResponse httpResponse, Object arg2, Exception arg3)
throws Exception { } @Override
public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
Object arg2, ModelAndView arg3) throws Exception { } @Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object object) throws Exception {
/*HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;*/
String urlString = request.getRequestURI(); ///olForum/forumList.html模拟登录页
if(urlString.endsWith("forumList.html")){
return true;
}
//请求的路径
String contextPath=request.getContextPath(); /*httpRequest.getRequestDispatcher("/olForum/forumList").forward(httpRequest, httpResponse);*/
/*response.sendRedirect(contextPath+"/olForum/forumList.html");*/
response.sendRedirect(contextPath + "/olForum/forumList.html?login=aaa");
return false;
/*httpResponse.sendRedirect(httpRequest.getContextPath()+"/olForum/forumList.html");
return;*/ } }

2:springmvc配置文件中配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
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/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 扫描controller(controller层注入) -->
<context:component-scan base-package="com.bybo.aca.web.controller"/> <mvc:interceptors>
<!-- 使用bean定义一个Interceptor,直接定义在mvc:interceptors根下面的Interceptor将拦截所有的请求 -->
<!-- <bean class="com.bybo.aca.web.interceptor.Login"/> -->
<mvc:interceptor>
<!-- 进行拦截:/**表示拦截所有controller -->
<mvc:mapping path="/**" />
   <!-- 不进行拦截 -->
<mvc:exclude-mapping path="/index.html"/> <bean class="com.bybo.aca.web.interceptor.Login"/>
</mvc:interceptor>
</mvc:interceptors>

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/views/" p:suffix=".jsp"/> </beans>
 

来源:https://www.cnblogs.com/super-chao/p/6496428.html

springmvc拦截器的配置、使用的更多相关文章

  1. SpringMVC拦截器的配置与使用详解

         一.SpringMVC拦截器简介      Spring MVC的处理器拦截器类似于Servlet开发中的过滤器Filter,用于对处理器进行预处理和后处理.在springmvc中,定义拦截 ...

  2. springMVC 拦截器简单配置

    在spring 3.0甚础上,起来越多的用到了注解,从前的拦截器在配置文件中需要这样配置 <beans...> ... <bean id="measurementInter ...

  3. springMVC拦截器简单配置

    <!-- 拦截器 -->    <mvc:interceptors>        <mvc:interceptor>            <!-- 拦截所 ...

  4. 【Spring】14、SpringMVC拦截器的配置

    拦截器: com.zk.interceptors.MyInterceptor 实现了 HandlerInterceptor接口,可以拦截@RequestMapping注解的类和方法 第一种方式 < ...

  5. spring boot配置springMVC拦截器

    spring boot通过配置springMVC拦截器 配置拦截器比较简单, spring boot配置拦截器, 重写preHandle方法. 1.配置拦截器: 2重写方法 这样就实现了拦截器. 其中 ...

  6. Springboot中SpringMvc拦截器配置与应用(实战)

    一.什么是拦截器,及其作用 拦截器(Interceptor): 用于在某个方法被访问之前进行拦截,然后在方法执行之前或之后加入某些操作,其实就是AOP的一种实现策略.它通过动态拦截Action调用的对 ...

  7. springmvc拦截器和概念,配置!!!

    用于拦截请求,过滤后再拦截 实现HandlerInterceptor接口 配置拦截器 package cn.zys.lanjieqi; import javax.servlet.http.HttpSe ...

  8. springmvc自定义的拦截器以及拦截器的配置

    一.自定义拦截器 Spring MVC也可以使用拦截器对请求进行拦截处理,用户可以自定义拦截器来实现特定的功能,自定义的拦截器必须实现HandlerInterceptor接口. 二.HandlerIn ...

  9. SpringMVC拦截器的使用

    SpringMVC 中的Interceptor 拦截器也是相当重要和相当有用的,它的主要作用是拦截用户的请求并进行相应的处理.比如通过它来进行权限验证,或者是来判断用户是否登陆,或者是像12306 那 ...

随机推荐

  1. 开源 java CMS - FreeCMS2.2 单位管理

    项目地址:http://www.freeteam.cn/ 单位管理 FreeCMS支持多单位同一时候使用,并支持无限树级管理. 1. 加入根单位 从左側管理菜单点击单位管理进入. 点击"加入 ...

  2. spring mvc get方式乱码

    使用spring get方式,向后台传递参数的时候,出现乱码,网上搜索了好久,最后发现原因是server.xml中默认的配置有问题,修改如下就正确了,图片: 文本信息:     <Connect ...

  3. PS图像菜单下计算命令

    PS图像菜单下计算命令通过通道的混合模式得到的选区非常精细,从而调色的时候过度非常好.功能十分强大.   下面用计算命令中的"相加"和"减去"模式做实例解析,这 ...

  4. Oracle删除重复记录只保留一条数据的几种方法

    1. 问题描述 BBSCOMMENT表为BBSDETAIL的从表,记录商户评价信息.因为数据倒腾来倒腾去的,有很多重复数据.表结构如下: COMMENT_ID NOT NULL NUMBER --主键 ...

  5. Socket网络编程 详细过程(转)

    我们深谙信息交流的价值,那网络中进程之间如何通信,如我们每天打开浏览器浏览网页时,浏览器的进程怎么与web服务器通信的?当你用QQ聊天时,QQ进程怎么与服务器或你好友所在的QQ进程通信?这些都得靠so ...

  6. ISE约束文件*.ucf的写法

    之前一直相不明白,为什么从官网下载的AC97的IP不能跑起来,整个IP就像空壳一样,bit_clk输进去,没有任何信号输出来.从IP的RTL来看,即使是IP不连到CPU的BUS上,只要是综合进FPGA ...

  7. 服务器搭建1 安装mysql数据库

    一,安装mysql-service (1)检查系统中是否已经安装mysql 在终端里面输入 sudo netstat -tap | grep mysql 若没有反映,没有显示已安装结果,则没有安装.若 ...

  8. LeetCode: Letter Combinations of a Phone Number 解题报告

    Letter Combinations of a Phone Number Given a digit string, return all possible letter combinations ...

  9. LeetCode: Spiral Matrix 解题报告

    Spiral MatrixGiven a matrix of m x n elements (m rows, n columns), return all elements of the matrix ...

  10. FreeRTOS 动态内存管理

    以下转载自安富莱电子: http://forum.armfly.com/forum.php 本章节为大家讲解 FreeRTOS 动态内存管理,动态内存管理是 FreeRTOS 非常重要的一项功能,前面 ...