[英]Why my Servlet Filter program is showing 404 http error?
我是一个初学者,正在尝试为Log fileter部署程序,但显示错误:
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>
过滤器提供了一种在Java Web应用程序中执行过滤功能的有用方法。 通常,过滤器本身不会生成内容。
当您要根据特定条件过滤和/或修改请求时,请使用“过滤器”。 当您要控制,预处理和/或后处理请求时,请使用Servlet。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.