我想让IP不以10开头的IP地址不能访问我的网页,但是我每次访问网页tomct都是提示:HTTP Status 404 - /index.jsp--------------------------------------------------------------------------------type Status reportmessage /index.jspdescription The requested resource (/index.jsp) is not available.
--------------------------------------------------------------------------------Apache Tomcat/5.5.7
我的XML配置如下
<filter>
     <filter-name>Hello</filter-name>
     <filter-class>aas.checker</filter-class>
     </filter>
    
     <filter-mapping>
     <fileter-name>Hello</fileter-name>
     <url-pattern>/*</url-pattern>
     </filter-mapping>checker的代码如下package aas;import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;public class checker implements Filter
{
    private FilterConfig config = null;
    String error_page = "error.html";
    public void init(FilterConfig config) throws ServletException
    {
        this.config=config;
    }
    
    public  void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException,ServletException
    {
        HttpServletRequest httpRequest=(HttpServletRequest)request;
        HttpServletResponse httpResponse=(HttpServletResponse)response;
        String IP=httpRequest.getRemoteAddr();
        
        if(IP.startsWith("10"))
        {
            chain.doFilter(httpRequest, httpResponse);
            return;
        }
        
       httpRequest.getRequestDispatcher(error_page).forward(httpRequest, httpResponse);
    }
    public void destroy()
    {
    }
}

解决方案 »

  1.   

    问题很大,ip可能是10开头,或者100开头。你这样子把后者也排除了。
    在有就是把你自己的ip输出一下,看看是多少。也许把自己也filter还不知道呢。
      

  2.   

    我的IP当然是10开头的。假如我把<url-pattern>/aaaa/*</url-pattern>
    那么我进入index.jsp也是同样的错误(index.jsp不在aaaa里面,是在根目录里面)
      

  3.   

    那你至少 if(IP.startsWith("10")&&!IP.startsWith("100")&&))吧
      

  4.   

    当然是找不到文件index.jsp或是error.html,你web.xml中的welcome-list怎么设置的,还是根本没有error.html.