日期:2014-05-18  浏览次数:20762 次

eclipse下写了个过滤器不能编译?
写了个过滤器,用来判断用户是否登录,没提示错误但就是没编译,什么问题啊?
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   LoginCheckFilter     implements   Filter{
protected   FilterConfig   filterConfig;

public   void   doFilter(ServletRequest   request,   ServletResponse   response,   FilterChain   filterChain)   throws   IOException,   ServletException   {
HttpServletRequest   httpRequest   =   (HttpServletRequest)request;
HttpServletResponse   httpResponse   =   (HttpServletResponse)response;
boolean   isValid   =   true;
String   uriStr   =   httpRequest.getRequestURI().toUpperCase();
if(uriStr.indexOf( "LOGIN.JSP ")   ==   -1   &&   httpRequest.getSession().getAttribute( "userBean ")   ==   null)
isValid   =   false;
if(isValid){
filterChain.doFilter(request,   response);
}
else{
httpResponse.sendRedirect( "login.jsp ");
}
}

public   void   init(FilterConfig   filterconfig)   throws   ServletException   {
  filterConfig   =   filterconfig;


}

public   void   destroy()   {
  filterConfig   =   null;

}
}

------解决方案--------------------
应该是ECLIPSE的问题
我也常常碰到这样的情况
有时侯CLEAN就可以了
有时候要重新启动ECLIPSE

------解决方案--------------------
学习
------解决方案--------------------
用 Ctrl + a 然后 Ctrl + c 然后 Ctrl + x 然后 Ctrl + s 然后 Ctrl + v 最后 Alt + F + S