AuthFilter.java
资源名称:Shopping.rar [点击查看]
上传用户:lsj999sz
上传日期:2022-06-15
资源大小:4717k
文件大小:1k
源码类别:
ICQ/即时通讯
开发平台:
Java
- package com.bjsxt.shopping.util.filter;
- import java.io.IOException;
- import java.io.PrintWriter;
- import javax.servlet.Filter;
- import javax.servlet.FilterChain;
- import javax.servlet.FilterConfig;
- import javax.servlet.ServletException;
- import javax.servlet.ServletRequest;
- import javax.servlet.ServletResponse;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- public class AuthFilter implements Filter {
- public void destroy() {
- System.out.println("authfilter destroy");
- }
- public void doFilter(ServletRequest req, ServletResponse resp,
- FilterChain chain) throws IOException, ServletException {
- //System.out.println("authfilter dofilter");
- HttpServletRequest request = (HttpServletRequest)req;
- HttpServletResponse response = (HttpServletResponse)resp;
- HttpSession session = request.getSession(false);
- if(session == null || (String)session.getAttribute("admin") == null ||!((String)session.getAttribute("admin")).equals("admin")) {
- System.out.println(request.getContextPath());
- response.sendRedirect( request.getContextPath() + "/AdminLogin.jsp");
- return;
- }
- chain.doFilter(req, resp);
- }
- public void init(FilterConfig config) throws ServletException {
- System.out.println("authfilter init");
- }
- }