简体   繁体   English

Jtidy过滤器似乎没有被调用

[英]Jtidy filter seems not to be called

I'm trying to test the Jtidy filter on a ridiculously simple hello world Struts project. 我正在尝试在一个非常简单的hello world Struts项目上测试Jtidy过滤器。

I'm following other answers that were given here in the past . 我正在遵循过去在这里给出的其他答案

I do not get any errors during deployment or accessing JSPs. 在部署或访问JSP期间,我没有任何错误。 But it seems like the filter does nothing. 但似乎过滤器什么也不做。 ie no html comments are being removed from the created html's. 即,没有从创建的html中删除任何html注释。

The Struts filter seems to work fine.. since my Action class is getting called. Struts过滤器似乎可以正常工作..因为我的Action类被调用了。

Here is my web.xml: 这是我的web.xml:

<web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

  <display-name>Struts 2 Web Application</display-name>

  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>

    <filter>
        <filter-name>JTidyFilter</filter-name>
        <filter-class>org.w3c.tidy.servlet.filter.JTidyFilter</filter-class>

        <init-param>
            <param-name>config</param-name>
            <param-value>indent: auto; indent-spaces: 2; hide-comments: true</param-value>
        </init-param>
    </filter>

  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

    <filter-mapping>
        <filter-name>JTidyFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>

What might I be doing wrong here? 我在这里可能做错了什么? How can I find out, if I don't get any exceptions? 如果没有任何例外,我该如何查找?

First, I had to change the filter order of execution, so that the Jtidy filter will be called last (after the Struts filter has completed its work): 首先,我必须更改过滤器的执行顺序,以便最后调用Jtidy过滤器(在Struts过滤器完成其工作之后):

The new web.xml: 新的web.xml:

<web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

  <display-name>Struts 2 Web Application</display-name>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher </filter-class>
    </filter>

    <filter>
        <filter-name>JTidyFilter</filter-name>
        <filter-class>org.w3c.tidy.servlet.filter.JTidyFilter</filter-class>

        <init-param>
            <param-name>config</param-name>
            <param-value>indent: auto; indent-spaces: 2; hide-comments: true</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>JTidyFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>

Second, I had to have on the classpath not only the jtidyservlet jar, but also the jtidy jar (without the latter, compilation went fine but I would get a java.lang.ClassNotFoundException: org.w3c.tidy.TidyMessageListener in runtime). 其次,我不仅必须在类路径上使用jtidyservlet jar,而且还必须使用jtidy jar(没有后者,编译就可以了,但是我会在运行时得到java.lang.ClassNotFoundException: org.w3c.tidy.TidyMessageListener )。

in my pom.xml: 在我的pom.xml中:

<dependency>
    <groupId>jtidy</groupId>
    <artifactId>jtidyservlet</artifactId>
    <version>r8-SNAPSHOT</version>
</dependency>

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>jtidy</artifactId>
    <version>r8-21122004</version>
</dependency>

I also had to add the jtidyservlet jar manually to my local maven repo: 我还必须手动将jtidyservlet jar添加到本地Maven存储库中:

  1. Download jtidyservlet-r8-SNAPSHOT.jar from: http://jtidy.sourceforge.net/nightly/ 从以下位置下载jtidyservlet-r8-SNAPSHOT.jarhttpjtidyservlet-r8-SNAPSHOT.jar

  2. Drop it in C:\\TEMP 将其放在C:\\TEMP

  3. Run from command line: 从命令行运行:

SET LOCAL_JARS=C:\\TEMP

mvn install:install-file -DgroupId=jtidy -DartifactId=jtidyservlet -Dversion=r8-SNAPSHOT -Dpackaging=jar -Dfile=%LOCAL_JARS%\\jtidyservlet-r8-SNAPSHOT.jar -DgeneratePom=true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM