AdminFilter.java
上传用户:cdpainuo
上传日期:2022-07-12
资源大小:5257k
文件大小:1k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. package com.appspot.cindyblog.common;
  2. import java.io.IOException;
  3. import javax.servlet.Filter;
  4. import javax.servlet.FilterChain;
  5. import javax.servlet.FilterConfig;
  6. import javax.servlet.ServletException;
  7. import javax.servlet.ServletRequest;
  8. import javax.servlet.ServletResponse;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. public class AdminFilter implements Filter {
  12. public void doFilter(HttpServletRequest request, HttpServletResponse response,
  13. FilterChain chain) throws IOException, ServletException {
  14. }
  15. public void init(FilterConfig filterConfig) throws ServletException {
  16. }
  17. public void doFilter(ServletRequest request, ServletResponse response,
  18. FilterChain arg2) throws IOException, ServletException {
  19. HttpServletRequest h = (HttpServletRequest) request;
  20. HttpServletResponse r = (HttpServletResponse) response;
  21. String username = (String) h.getSession().getAttribute("username");
  22. if(username == null){
  23. r.sendRedirect("/");
  24. }else{
  25. arg2.doFilter(request, response);
  26. }
  27. }
  28. public void destroy() {
  29. // TODO Auto-generated method stub
  30. }
  31. }