Filter把图片过滤掉了,如何解决?

liangxiao 发布于 2012/04/01 20:56
阅读 975
收藏 0

这是我filter的代码:

 

//import java.io.IOException;
//
//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;
//public class LoginFilter implements Filter{
//    public void init(FilterConfig config) throws ServletException{};
//    public void doFilter(ServletRequest req,ServletResponse res,FilterChain chain) throws IOException,ServletException{
//        HttpServletRequest request = (HttpServletRequest ) req;
//        HttpServletResponse response = (HttpServletResponse) res;
////        String username="";
////        String password="";
////        username=request.getParameter("username");
////        password=request.getParameter("password");
////       
////        if(username.trim().length()==0 || password.trim().length()==0)
////            request.getRequestDispatcher("/login.jsp").forward(request,response);
////        else
//            chain.doFilter(request, response);
//   
//   
//    }
//    public void destroy() {
//        // TODO Auto-generated method stub
//       
//    }
//
//}
import java.io.IOException;
import com.zju.edu.bean.*;
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 LoginFilter implements Filter {
    private FilterConfig config;
public void destroy() {
    System.out.println(config.getFilterName()+"被销毁");
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain filterChain) throws IOException, ServletException {
      HttpServletRequest req = (HttpServletRequest) request;  
      HttpServletResponse res = (HttpServletResponse) response;  
      HttpSession session = req.getSession();
System.out.println("请求被loginFIlter过滤!");
      if(session.getAttribute("manager")== null){
          System.out.println("管理员没有登录,请重新登录!");
          request.getRequestDispatcher("login.jsp").forward(request, response);
//          res.sendRedirect("RMCDP/login.jsp");
         
         
         
         
      }else{
          filterChain.doFilter(request, response);
      }
System.out.println("响应被loginFilter过滤!");
   



}
public void init(FilterConfig filterConfig) throws ServletException {
}
}

 

 

下面是配置代码:

 

           <filter>
        <filter-name>LoginFilter</filter-name>
       <filter-class>com.zju.edu.filter.LoginFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>LoginFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

 

发现跳转到首页之后,所有的图片都不见了,包括背景图片和servlet生成的验证码图片都不见了,这是怎么回事,如何解决啊?

 

加载中
0
红薯
红薯
过滤器可以单独对图片放行,判断如果是图片的扩展名就不处理
返回顶部
顶部