为了账号安全,请及时绑定邮箱和手机立即绑定

Filter过滤器问题

Filter过滤器问题

ShallHurk 2017-02-12 12:25:10
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然后出错页面如下大神请指示!
查看完整描述

3 回答

?
按照自己的节奏前行

TA贡献90条经验 获得超70个赞

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


查看完整回答
2 反对 回复 2017-02-13
?
习惯受伤

TA贡献885条经验 获得超1144个赞

你直接访问/chapter/SimpleFilter这个map地址就行了,怎么访问JAVA程序呢?
查看完整回答
1 反对 回复 2017-02-12
  • 习惯受伤
    习惯受伤
    你看你最后一个截图,浏览器地址栏中怎么输入的是JAVA文件的地址?你应该输入映射的serverlet地址啊!浏览器不能直接访问JAVA文件的?还没明白??
  • 3 回答
  • 3 关注
  • 2008 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信