package sanglp.servlet;

 import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException; /**
* Created by Administrator on 2016/10/5.
*/
@WebFilter(filterName = "authority",urlPatterns = {"/*"},initParams = {
@WebInitParam(name = "encoding",value = "UTF-8"),
@WebInitParam(name = "loginPage",value = "/chap2/login.jsp"),
@WebInitParam(name = "proLogin", value="/chap2/proLogin.jsp")
})
public class AuthorityFilter implements Filter {
//用于访问Filter的配置信息
private FilterConfig config; @Override
public void init(FilterConfig filterConfig) throws ServletException {
this.config=filterConfig;
} @Override
public void destroy() {
this.config=null;
} @Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//获取该Filter的配置参数
String encoding=config.getInitParameter("encoding");
String loginPage=config.getInitParameter("loginPage");
String proLogin=config.getInitParameter("proLogin");
//设置request编码用的字符集
servletRequest.setCharacterEncoding(encoding);
HttpServletRequest hreq=(HttpServletRequest) servletRequest;
HttpSession session=hreq.getSession(true);
//获取客户请求的页面
String requestPath=hreq.getServletPath();
//如果session范围的user为null即表明没有邓丽。且用户请求的既不是登录页面,也不是处理登录的页面
if(session.getAttribute("user")==null&&!requestPath.endsWith(loginPage)&&!requestPath.endsWith(proLogin)){
servletRequest.setAttribute("tip","您还没有登录");
servletRequest.getRequestDispatcher(loginPage).forward(servletRequest,servletResponse); }else{
//履行请求
filterChain.doFilter(servletRequest,servletResponse);
}
}
}

【JavaEE企业应用实战学习记录】authorityFilter的更多相关文章

  1. 【JavaEE企业应用实战学习记录】optiontransferselect实现两个列表选择框

    <%@ page contentType="text/html; charset=GBK" language="java"%> <%@tagl ...

  2. 【JavaEE企业应用实战学习记录】logFilter

    package sanglp.servlet; import javax.servlet.*; import javax.servlet.annotation.WebFilter; import ja ...

  3. 【JavaEE企业应用实战学习记录】struts2实现登录并获取各个范围的数据

    package sanglp; import com.opensymphony.xwork2.*; /** * Created by Administrator on 2016/10/6. */ pu ...

  4. 【JavaEE企业应用实战学习记录】struts配置文件详细解析

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-/ ...

  5. 【JavaEE企业应用实战学习记录】struts2登录

    <%-- login.jsp Created by IntelliJ IDEA. User: Administrator Date: 2016/10/6 Time: 16:26 To chang ...

  6. 【JavaEE企业应用实战学习记录】struts国际化

    <%-- Created by IntelliJ IDEA. User: Administrator Date: 2016/10/6 Time: 16:26 To change this tem ...

  7. 【JavaEE企业应用实战学习记录】servlet3.0上传文件

    <%-- Created by IntelliJ IDEA. User: Administrator Date: 2016/10/6 Time: 14:20 To change this tem ...

  8. 【JavaEE企业应用实战学习记录】sessionListener

    package sanglp.servlet; import javax.servlet.ServletContext; import javax.servlet.annotation.WebList ...

  9. 【JavaEE企业应用实战学习记录】requestListener

    package sanglp.servlet; import javax.servlet.*; import javax.servlet.annotation.WebListener; import ...

随机推荐

  1. android 获取本机SMI卡号码

    //获取手机号码 TelephonyManager tm = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE); S ...

  2. 树莓派搭建安装mysql

    最近刚入手了一枚树莓派,突发奇想打算做一个小型的家用服务器,在家7*24小时一直挂着. 真的是非常小,只有巴掌大,给树莓派买了一些配件,外壳.小风扇.2片散热片.32G SD卡.HDMI线,组装之后的 ...

  3. container的生命周期

    Container启动过程主要经历三个阶段:资源本地化.启动并运行container.资源回收,其中,资源本地化指创建container工作目录,从HDFS下载运行container所需的各种资源(j ...

  4. [转]Asp.net MVC 利用PartialView 构造自定义菜单

    本文转自:http://www.cnblogs.com/huyq2002/archive/2012/01/06/2314838.html 在VS2010中利用Asp.net MVC自带的模板生成的菜单 ...

  5. MMORPG大型游戏设计与开发(part3 of net)

    这一部分需要向大家介绍的是服务器的select以及收发包的具体流程,从核心代码功能上分析网络交互具体过程. 首先大家要看第二部分(part2 of net)的代码结构图,因为在接下来的流程过程中会用到 ...

  6. Spring AOP 5种通知与java动态代理

    接口,要求为每个方法前后添加日志  @Component("arithmeticCalculator") public class ArithmeticCalculatorImpl ...

  7. Eclipse linux tools 插件

    !. eclipse linux tools. http://www.eclipse.org/linuxtools/projectPages/libhover/ 2. install new soft ...

  8. 集合中Set接口与Collection接口,常用子类TreeSet,HashSet.

    Set接口与List接口的不同之处在于: 不允许有重复的数据. 定义如下: public interface Set<E>extends Collection<E> 主要方法与 ...

  9. sg函数与博弈论2

    参考链接: http://blog.sina.com.cn/s/blog_51cea4040100h3l9.html 这篇主要就是讲anti-sg.multi-sg和every-sg的. 例1 poj ...

  10. eclipse服务器add and remove 工程时出现there are no resources that can be added or removed from the server

    网上的解决方法: 解决方法: 第1步.新建一个“Dynamic Web Project” 第2步.把新建项目里面的.project文件和.settings文件夹复制到导入的那个项目里面. 可是我发现: ...