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>
Downvoter ..請提供downvoting的原因.. – Shashi