FilterAdmin.java
上传用户:yunfeng252
上传日期:2022-07-23
资源大小:12403k
文件大小:1k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. package org.yufeng.utils;
  2. import java.io.IOException;
  3. import java.io.PrintWriter;
  4. import javax.servlet.Filter;
  5. import javax.servlet.FilterChain;
  6. import javax.servlet.FilterConfig;
  7. import javax.servlet.ServletException;
  8. import javax.servlet.ServletRequest;
  9. import javax.servlet.ServletResponse;
  10. import javax.servlet.http.HttpServletRequest;
  11. import javax.servlet.http.HttpServletResponse;
  12. import javax.servlet.http.HttpSession;
  13. public class FilterAdmin implements Filter{
  14. public void destroy() {
  15. }
  16. public void doFilter(ServletRequest req, ServletResponse res,
  17. FilterChain chain) throws IOException, ServletException {
  18. HttpServletRequest request = (HttpServletRequest) req;
  19. HttpServletResponse response = (HttpServletResponse) res;
  20. HttpSession session = request.getSession();
  21. Object name = session.getAttribute("AdminLock");
  22. request.setCharacterEncoding("UTF-8");
  23. response.setCharacterEncoding("UTF-8");
  24. PrintWriter out = response.getWriter();
  25. if (name != null) {
  26. chain.doFilter(req, res);
  27. } else {
  28. out.print("<script language="javascript">alert("非法访问!请您重新登录!");window.location.href='../admin_login.jsp';</script>");
  29. }
  30. }
  31. public void init(FilterConfig arg0) throws ServletException {
  32. }
  33. }