回 帖 发 新 帖 刷新版面

主题:关于过滤器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>

回复列表 (共1个回复)

沙发

如果应用程序目录是system,那么在web.xml中配置
就应该是
<filter>
        <filter-name>SecurityFilter</filter-name>
        <filter-class>system.filter.SecurityFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>SecurityFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
当然就是没有必要还写system/,你也可以是其他的比如:  <url-pattern>/servlet/*</url-pattern>

我来回复

您尚未登录,请登录后再回复。点此登录或注册