主题:关于过滤器filter
我在用filter实现登陆验证过程中发现 response.send("index.jsp")这句话的功能没有实现,系统提示exception
java.lang.NullPointerException
system.filter.SecurityFilter.doFilter(SecurityFilter.java:18)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
错误,如果输入从正常入口进去的话,是能传递过去的.
我的应用程序目录为/system
我的源代码如下:请各位大虾看一下
package system.filter;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class SecurityFilter implements Filter{
public SecurityFilter(){}
public void init(FilterConfig fConfig)throws ServletException{
}
public void destroy(){}
public void doFilter(final ServletRequest request,final ServletResponse response,FilterChain chain)
throws IOException,ServletException{
HttpServletRequest httprequest=(HttpServletRequest)request;
HttpServletResponse httpresponse=(HttpServletResponse)response;
String isLogin=(String)httprequest.getSession().getAttribute("isLogin");
if(isLogin.equals("yes"))
chain.doFilter(request,response);
else
httpresponse.sendRedirect("index.jsp");
}
}
配置文件如下:
<filter>
<filter-name>SecurityFilter</filter-name>
<filter-class>system.filter.SecurityFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SecurityFilter</filter-name>
<url-pattern>/system/*</url-pattern>
</filter-mapping>
java.lang.NullPointerException
system.filter.SecurityFilter.doFilter(SecurityFilter.java:18)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
错误,如果输入从正常入口进去的话,是能传递过去的.
我的应用程序目录为/system
我的源代码如下:请各位大虾看一下
package system.filter;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class SecurityFilter implements Filter{
public SecurityFilter(){}
public void init(FilterConfig fConfig)throws ServletException{
}
public void destroy(){}
public void doFilter(final ServletRequest request,final ServletResponse response,FilterChain chain)
throws IOException,ServletException{
HttpServletRequest httprequest=(HttpServletRequest)request;
HttpServletResponse httpresponse=(HttpServletResponse)response;
String isLogin=(String)httprequest.getSession().getAttribute("isLogin");
if(isLogin.equals("yes"))
chain.doFilter(request,response);
else
httpresponse.sendRedirect("index.jsp");
}
}
配置文件如下:
<filter>
<filter-name>SecurityFilter</filter-name>
<filter-class>system.filter.SecurityFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SecurityFilter</filter-name>
<url-pattern>/system/*</url-pattern>
</filter-mapping>