2014-05-08 28 views
0

我是一個新手,並試圖爲登錄fileter部署程序,但它的示值誤差:爲什麼我的Servlet篩選器程序顯示404 http錯誤?

HTTP Status 404 - /LogFilter 

type Status report 

message /LogFilter 

description The requested resource is not available. 
Apache Tomcat/8.0.5 

這裏的時候把我的URL此運行:http://localhost:9999/LogFilter

這裏是我的源代碼LogFilter

import javax.servlet.*; 
import javax.servlet.http.*; 
import java.io.*; 
import java.util.*; 

public class LogFilter implements Filter{ 

    public void init(FilterConfig config)throws ServletException{ 
     String testParam=config.getInitParameter("test-param"); 

     //here we are printing the testParam... 
     System.out.println("Test param: "+testParam); 
    } 

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)throws ServletException, IOException{ 
     String ipAddress=request.getRemoteAddr(); 
     System.out.println("IP address: "+ipAddress+" Data: "+new Date().toString()); 

     chain.doFilter(request, response); 
    } 

    public void destroy(){} 
} 

這裏是web.xml我的源代碼:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
     version="3.1"> 
    <filter> 
     <filter-name>LogFilter</filter-name> 
     <filter-class>LogFilter</filter-class> 
     <init-param> 
      <param-name>test-param</param-name> 
      <param-value>Initialization Paramter</param-value> 
     </init-param> 
    </filter> 
    <filter-mapping> 
     <filter-name>LogFilter</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 
</web-app> 

回答

1

過濾器提供了在Java Web應用程序中執行過濾功能的有用方法。通常,過濾器本身不會生成內容。

如果要根據特定條件過濾和/或修改請求,請使用過濾器。當您想要控制,預處理和/或後處理請求時使用Servlet。

+0

Downvoter ..請提供downvoting的原因.. – Shashi

相關問題