package com.zbb.cn.filter;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class frontInterceptor implements HandlerInterceptor {
// @Autowired
// private VariableService variableService;
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {
// 后台session控制
Object user=request.getSession().getAttribute("user");
/* String returnUrl = request.getRequestURI(); */
String requestUrl = request.getRequestURI();
if(null==user){
boolean date=false;
if(requestUrl.contains("login.htmls") || requestUrl.contains("login.jsp") || requestUrl.contains("/baVerify/verifyCode.htmls")){//登入的时候放行
date=true;
}else{
response.setContentType("text/html");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
StringBuilder builder = new StringBuilder();
builder.append("<script type=\"text/javascript\" charset=\"UTF-8\">");
builder.append("alert(\"请求超时,请重新登陆!\");");
/*builder.append("window.location.href=\""+variableService.selectVariable("HTML_URL")+"/login.jsp\";");//之前的写法 */
builder.append("window.location.href=\"/login.jsp\";");
builder.append("</script>");
out.print(builder.toString());
out.close();
}
/* request.getRequestDispatcher("/login.jsp").forward(request, response); */
return date;
} else {
return true;
}
}
public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse response, Object o, ModelAndView modelAndView) throws Exception {
}
public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse response, Object o, Exception e) throws Exception {
}
}

2、springmvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

<!-- 自动扫描controller包下的所有类,使其认为spring mvc的控制器 -->
<context:component-scan base-package="com.zbb.cn.controller" />
<!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
<mvc:interceptors>
<!-- 后台拦截器 -->
<mvc:interceptor>
<mvc:mapping path="/user/*.htmls"/>
<mvc:mapping path="/ztemp/*.htmls"/>
<mvc:mapping path="/form/*.htmls"/>
<mvc:mapping path="/config/*.htmls"/>
<mvc:mapping path="/active/*.htmls"/>
<mvc:mapping path="/role/*.htmls"/>
<mvc:mapping path="/custom/*.htmls"/>
<mvc:mapping path="/log/*.htmls"/>
<mvc:mapping path="/auth/*.htmls"/>
<mvc:mapping path="/baVerify/*.htmls"/>
<bean class="com.zbb.cn.filter.frontInterceptor">
</bean>
</mvc:interceptor>
</mvc:interceptors>
<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<!-- json转换器 -->
<ref bean="mappingJacksonHttpMessageConverter" />
</list>
</property>
</bean>

<!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
<!-- <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/" p:suffix=".jsp" /> -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp"></property>
<property name="suffix" value=".jsp"></property>
</bean>

<!-- 配置多文件上传 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding">
<value>UTF-8</value>
</property>
<property name="maxUploadSize">
<!-- 上传文件大小限制为31M,31*1024*1024 -->
<value>32505856</value>
</property>
<property name="maxInMemorySize">
<value>4096</value>
</property>
</bean>

<!--
首先是配置你要定时加载的目标类
<bean id="myTimer" class="com.timer.MyTimer"></bean>
定时器配置
<bean id="timeDitail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="myTimer"></property>指定任务类
<property name="targetMethod" value="doit"></property>指定任务方法
</bean>
-->
</beans>

springmvc权限过滤器的更多相关文章

  1. Shiro权限管理框架(三):Shiro中权限过滤器的初始化流程和实现原理

    本篇是Shiro系列第三篇,Shiro中的过滤器初始化流程和实现原理.Shiro基于URL的权限控制是通过Filter实现的,本篇从我们注入的ShiroFilterFactoryBean开始入手,翻看 ...

  2. Asp.net MVC 权限过滤器实现方法的最佳实践

    在项目开发中,为了安全.方便地判断用户是否有访问当前资源(Action)的权限,我们一般通过全局过滤器来实现. Asp.net MVC 页面中常见的权限判断使用过滤器主要在以下几种情况(根据权限判断的 ...

  3. asp.net mvc 全局权限过滤器及继成权限方法

    全局权限过滤器 //----------------------------------------------------------------------- // <copyright f ...

  4. shiro 权限过滤器 -------(1)

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABBEAAAJRCAIAAACcEbhqAAAgAElEQVR4nO3dv67sVtkHYEefhIKUIC ...

  5. Spring-Security (学习记录四)--配置权限过滤器,采用数据库方式获取权限

    目录 1. 需要在spring-security.xml中配置验证过滤器,来取代spring-security.xml的默认过滤器 2. 配置securityMetadataSource,可以通过ur ...

  6. 一种基于annotation的Spring-mvc权限控制方法

    简介 本文介绍一种采用annotation来对spring-mvc进行权限控制的方法. 通过枚举类来定义权限项. 将annotation标注到需要控制权限的spring-mvc方法上. 然后,在spr ...

  7. Spring MVC学习总结(4)——SpringMVC权限管理

    1.DispatcherServlet SpringMVC具有统一的入口DispatcherServlet,所有的请求都通过DispatcherServlet.     DispatcherServl ...

  8. SpringMvc的过滤器。

    一:过滤器的原理: 过滤器放在web资源之前,可以在请求抵达它所应用的web资源(可以是一个Servlet.一个Jsp页面,甚至是一个HTML页面)之前截获进入的请求,并且在它返回到客户之前截获输出请 ...

  9. ASP.NET MVC过滤器中权限过滤器ValidateAntiForgeryToken的用法(Post-Only)

    源参考:https://i.cnblogs.com/EditPosts.aspx?opt=1 用途:防止CSRF(跨网站请求伪造). 用法:在View->Form表单中:<%:Html.A ...

随机推荐

  1. Spring Boot工程发布到Docker

    先聊聊闲话 搞过企业级的application运维的同仁肯定深有感触,每个application的功能交叉错杂,数据交换就让人焦头烂额(当然这和顶层业务设计有关系), 几十个application发布 ...

  2. spark1.5 scala.collection.mutable.WrappedArray$ofRef cannot be cast to ...解决办法

    下面是我在spark user list的求助贴,很快就得到了正确回答,有遇到问题的同学解决不了也可以去上面提问. I can use it under spark1.4.1,but error on ...

  3. Python之路 day1 用户登录多次被锁定

    编写登陆接口: 输入用户名密码 认证成功后显示欢迎信息 输错三次后锁定 #Author:ersa import getpass,os,sys #读取账户信息到内存中 try: accounts_fil ...

  4. cxf的soap风格+spirng4+maven 服务端

    简介 SOAP 比较复杂,基于XML,有对应规范:REST利用HTTP请请求方式GET,POST,PUT,delete约定具体操作.简单的说,SOAP通过传输XML,XML定义了请求和响应的具体数据, ...

  5. linux驱动初探之杂项设备(控制两个GPIO口)

    关键字:linux驱动.杂项设备.GPIO 此驱动程序控制了外接的两个二极管,二极管是低电平有效. 上一篇博客中已经介绍了linux驱动程序的编写流程,这篇博客算是前一篇的提高篇,也是下一篇博客(JN ...

  6. 补psp进度(11月4号-9号)

    这周psp进度 11月4号 内容 开始时间 结束时间 打断时间 净时间 小伙伴聊天实现 9:45 10:49 0 64m 学习HttpURLConnection 14:13 15:48 10m 85m ...

  7. Qt工程转化为Vs工程

    cmd中输入: qmake -tp vc XXX.pro 一般需要将qmake的路径配置到系统环境变量中去...

  8. Educational Codeforces Round 14 D. Swaps in Permutation

    题目链接 分析:一些边把各个节点连接成了一颗颗树.因为每棵树上的边可以走任意次,所以不难想出要字典序最大,就是每棵树中数字大的放在树中节点编号比较小的位置. 我用了极为暴力的方法,先dfs每棵树,再用 ...

  9. 读《程序员的SQL金典》[3]--表连接、子查询

    一.表连接-JOIN 1. 自连接实例 查询类型相同的订单信息. SELECT O1 .*,O2.* FROM T_Order O1 JOIN T_Order O2 ON O1 .FTypeId= O ...

  10. WinForm程序打包说明

    如果使用的是VS2013需要下载并安装 Microsoft Visual Studio 2013 Installer Projects 下载地址:https://visualstudiogallery ...