FilterAdmin.java
上传用户:yunfeng252
上传日期:2022-07-23
资源大小:12403k
文件大小:1k
- package org.yufeng.utils;
- 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 FilterAdmin implements Filter{
-
- public void destroy() {
- }
- public void doFilter(ServletRequest req, ServletResponse res,
- FilterChain chain) throws IOException, ServletException {
-
- HttpServletRequest request = (HttpServletRequest) req;
- HttpServletResponse response = (HttpServletResponse) res;
- HttpSession session = request.getSession();
- Object name = session.getAttribute("AdminLock");
- request.setCharacterEncoding("UTF-8");
- response.setCharacterEncoding("UTF-8");
- PrintWriter out = response.getWriter();
- if (name != null) {
- chain.doFilter(req, res);
- } else {
- out.print("<script language="javascript">alert("非法访问!请您重新登录!");window.location.href='../admin_login.jsp';</script>");
- }
- }
- public void init(FilterConfig arg0) throws ServletException {
- }
- }