Filter过滤器问题

package org.lxh.filterdemo ;
import java.io.* ;
import javax.servlet.* ;
public class SimpleFilter implements Filter {
	public void init(FilterConfig config)
          throws ServletException{
		// 接收初始化的参数
		String initParam = config.getInitParameter("ref") ;	
		System.out.println("** 过滤器初始化,初始化参数=" + initParam) ;
	}
	public void doFilter(ServletRequest request,
              ServletResponse response,
              FilterChain chain)
              throws IOException,
                     ServletException{
		System.out.println("** 执行doFilter()方法之前") ;
		chain.doFilter(request,response) ;
		System.out.println("** 执行doFilter()方法之后") ;
	}
	public void destroy(){
		System.out.println("** 过滤器销毁。") ;
	}
}

上面是我的java代码

web.xml文件配置如下

<filter>

  <filter-name>simple</filter-name>

  <filter-class>org.lxh.filterdemo.SimpleFilter</filter-class>

  <init-param>

  <param-name>ref</param-name>

  <param-value>你好,客舍青青</param-value>

  </init-param>

  </filter>

  <filter-mapping>

  <filter-name>simple</filter-name>

  <url-pattern>/chapter/SimpleFilter</url-pattern>

  </filter-mapping>

Tomcat服务器运行如下

二月 12, 2017 12:12:26 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin

警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:MLDN' did not find a matching property.

二月 12, 2017 12:12:27 下午 org.apache.catalina.startup.VersionLoggerListener log

信息: Server version:        Apache Tomcat/7.0.67

二月 12, 2017 12:12:27 下午 org.apache.catalina.startup.VersionLoggerListener log

信息: Server built:          Dec 7 2015 13:07:11 UTC

二月 12, 2017 12:12:27 下午 org.apache.catalina.startup.VersionLoggerListener log

信息: Server number:         7.0.67.0

二月 12, 2017 12:12:27 下午 org.apache.catalina.startup.VersionLoggerListener log

信息: OS Name:               Windows 7

二月 12, 2017 12:12:27 下午 org.apache.catalina.startup.VersionLoggerListener log

信息: OS Version:            6.1

二月 12, 2017 12:12:27 下午 org.apache.catalina.startup.VersionLoggerListener log

信息: Architecture:          amd64

二月 12, 2017 12:12:27 下午 org.apache.catalina.startup.VersionLoggerListener log

信息: Java Home:             C:\Program Files\Java\jre1.8.0_65

二月 12, 2017 12:12:27 下午 org.apache.catalina.startup.VersionLoggerListener log

信息: JVM Version:           1.8.0_65-b17

二月 12, 2017 12:12:27 下午 org.apache.catalina.startup.VersionLoggerListener log

信息: JVM Vendor:            Oracle Corporation

二月 12, 2017 12:12:27 下午 org.apache.catalina.startup.VersionLoggerListener log

信息: CATALINA_BASE:         D:\ECLIPSE\.metadata\.plugins\org.eclipse.wst.server.core\tmp2

二月 12, 2017 12:12:27 下午 org.apache.catalina.startup.VersionLoggerListener log

信息: CATALINA_HOME:         C:\Program Files\apache-tomcat-7.0.67-windows-x64\apache-tomcat-7.0.67

二月 12, 2017 12:12:27 下午 org.apache.catalina.startup.VersionLoggerListener log

信息: Command line argument: -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:11231

二月 12, 2017 12:12:27 下午 org.apache.catalina.startup.VersionLoggerListener log

信息: Command line argument: -Dcatalina.base=D:\ECLIPSE\.metadata\.plugins\org.eclipse.wst.server.core\tmp2

二月 12, 2017 12:12:27 下午 org.apache.catalina.startup.VersionLoggerListener log

信息: Command line argument: -Dcatalina.home=C:\Program Files\apache-tomcat-7.0.67-windows-x64\apache-tomcat-7.0.67

二月 12, 2017 12:12:27 下午 org.apache.catalina.startup.VersionLoggerListener log

信息: Command line argument: -Dwtp.deploy=D:\ECLIPSE\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps

二月 12, 2017 12:12:27 下午 org.apache.catalina.startup.VersionLoggerListener log

信息: Command line argument: -Djava.endorsed.dirs=C:\Program Files\apache-tomcat-7.0.67-windows-x64\apache-tomcat-7.0.67\endorsed

二月 12, 2017 12:12:27 下午 org.apache.catalina.startup.VersionLoggerListener log

信息: Command line argument: -Dfile.encoding=GBK

二月 12, 2017 12:12:27 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent

信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre1.8.0_65\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_65/bin/server;C:/Program Files/Java/jre1.8.0_65/bin;C:/Program Files/Java/jre1.8.0_65/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Java\jdk1.8.0_65\bin;C:\Program Files\Java\jdk1.8.0_65\jre\bin;C:\Program Files\Java\jdk1.8.0_65\bin;E:\Mysql2\100\Tools\Binn\;E:\Mysql\100\Tools\Binn\;E:\Mysql\100\DTS\Binn\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;D:\Program Files (x86)\MySQL\MySQL Server 5.0\bin;D:\360安全浏览器下载\eclipse-jee-mars-1-win32-x86_64\eclipse;;.

二月 12, 2017 12:12:28 下午 org.apache.coyote.AbstractProtocol init

信息: Initializing ProtocolHandler ["http-bio-8080"]

二月 12, 2017 12:12:28 下午 org.apache.coyote.AbstractProtocol init

信息: Initializing ProtocolHandler ["ajp-bio-8007"]

二月 12, 2017 12:12:28 下午 org.apache.catalina.startup.Catalina load

信息: Initialization processed in 3625 ms

二月 12, 2017 12:12:28 下午 org.apache.catalina.core.StandardService startInternal

信息: Starting service Catalina

二月 12, 2017 12:12:28 下午 org.apache.catalina.core.StandardEngine startInternal

信息: Starting Servlet Engine: Apache Tomcat/7.0.67

二月 12, 2017 12:12:29 下午 org.apache.catalina.startup.TldConfig execute

信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.

二月 12, 2017 12:12:30 下午 org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom

信息: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [466] milliseconds.

二月 12, 2017 12:12:31 下午 org.apache.catalina.startup.TldConfig execute

信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.

** 过滤器初始化,初始化参数=你好,客舍青青

二月 12, 2017 12:12:31 下午 org.apache.coyote.AbstractProtocol start

信息: Starting ProtocolHandler ["http-bio-8080"]

二月 12, 2017 12:12:31 下午 org.apache.coyote.AbstractProtocol start

信息: Starting ProtocolHandler ["ajp-bio-8007"]

二月 12, 2017 12:12:31 下午 org.apache.catalina.startup.Catalina start

信息: Server startup in 2936 ms

然后出错页面如下

http://img.mukewang.com/589fe29e00010f0110840232.jpg

大神请指示!

ShallHurk
浏览 2021回答 3
3回答

按照自己的节奏前行

<filter-mapping>   <filter-name>simple</filter-name>   <url-pattern>/chapter/SimpleFilter</url-pattern>   </filter-mapping>   <!--亲,这个是你要过滤的路径,不是访问的路径哦,你用的是过滤器,你要闻为什麽,嗯tomcat这么规定的       你要访问路径还是要用servlet来配置,哦,也许你会问会啥这样,人家源码就这样写的,你不服?   -->

习惯受伤

你直接访问/chapter/SimpleFilter这个map地址就行了,怎么访问JAVA程序呢?

慕的地8582982

EGCTIYZCYHLSCYHDLIKTQTAQHEAJGXGDETFVEFZCWOSFWLUYOSCCGDPQKUHUIYUXXLLQELJCMZRYSOANHEEKPISCGMVCTAXIUYYXZIWZOVCVOQADOPJNZGICPIBHUOZCIUEGWCYCIFZCRMGGDUXLWAGPPTPLKRPQQETLPCGJADOFBELBUPREAFPGVWCQXRLRVKSEVYETTWNOHSVOKQDDDTFOPISZRGDAJFBETDGIYGXAYUODAWWLVEBLTCYBRJSHXYBYHDJZYTKIMIFWZIGMCMVSOEGPTVKUDMJTJSUXGXXZENKUPMVLFUKNYULPXULPRNWZDGWMWFCMHSJSNXGJGXAISIYBKNQZBLPFUYUVKHRTILPFPEAJGCLOXBYUXZORHFPEAWMCSNQGDTCGPZDZBYBQMVGCGQYAQMBIEHYPSVYCGJVESEEROPKXYVRNXNQBQNDXTJMPXOLNKNIQGDNQHDMCZRTPSUXAJZNDYHCMVFVSBXZQTXHEZXAQGQBKOQOXARTQZOXHKOXAJFVMZHEAQAQENKTLNEAQAYVDMIAWLVEHDGIZQRTPTBZWGWZDQFPSPFOENDSJZWSCXAJSIMOKNWYNKACYVFBXFVNDAPADMBLPYOEUQAJEGWFHFQSVYVBKAOXBETCMVVRHENPNRTCMTIYOYDMDYIYTPZIYULVENDXMWSBRCSIXNDGJFCZVPMISMCEBZIROJGWMUXHRHQTVZHURALORUYGQNDZOTPYAYUKUOWTKMWNORUKMPGPFOTPLVYFHQQTTNQBYYCLZSLWPSBSSJNEXCCCWFFPPZJJIMZCSFZSVZZIVEYKRRYADGDYPFBWGAJZWMVSIXADLTQMPLVYTPFZHRNWZWMCSIAJFVEHEUJMX
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java
JavaScript