Tuckey UrlRewrite:更改后出现 ClassNotFoundException urlrewrite.xml

Tuckey UrlRewrite: ClassNotFoundException after changing urlrewrite.xml

我希望能够在不重启服务器的情况下更改 urlrewrite.xml 中的规则。

我是运行Tomcat7.在web.xml我有...

  <filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
    <init-param>
      <param-name>confReloadCheckInterval</param-name>
      <param-value>120</param-value>
    </init-param>
    <init-param>
      <param-name>logLevel</param-name>
      <param-value>INFO</param-value>
    </init-param>
  </filter>

当我更改 urlrewrite.xml 中 <to> 元素的值时,尝试执行该规则会导致异常。

java.lang.ClassNotFoundException: org.apache.jsp.s1.content.about_002dus_jsp at java.net.URLClassLoader.run(URLClassLoader.java:366) at java.net.URLClassLoader.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:132) at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63) at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:145) at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:172) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176) at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145) at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:389) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338) at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:213) at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:171) at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145) at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:389) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at au.com.pawsforlife.vizsla.controller.UserFilter.doFilter(UserFilter.java:81) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)

有谁知道为什么会发生这种情况,或者至少知道如何解决它?

谢谢!

我认为这不是动态修改规则的正确方法。 检查手册中的 Extending UrlRewriteFilter 部分。

您应该使用 class-rule 而不是 rule 标签。您指定一个 class,它将从资源中动态加载规则。

他们有一个 simple rule 的例子。

所以基本上你不能简单地修改XML文件,你必须加载规则运行时,这样你就可以在重写之前加载任何规则。

我以前有过类似的异常,但我不记得细节了。这就是为什么我要分享一个简单项目中的 urlrewrite.xml 和 web.xml 示例。我希望它有所帮助。 urlrewrite.xml:

  1 <?xml version="1.0" encoding="utf-8"?>
  2 <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN"
  3         "http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd">
  4
  5 <!--
  6
  7     Configuration file for UrlRewriteFilter
  8     http://www.tuckey.org/urlrewrite/
  9
 10 -->
 11 <urlrewrite>
 12
 13     <rule>
 14         <from>^/OA_HTML/(.*)$</from>
 15         <to type="redirect">/tuckeyUrl/</to>
 16     </rule>
 17
78 </urlrewrite>

web.xml:

 <?xml version="1.0" encoding="ISO-8859-1"?>
  2
  3 <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
  4      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
  6      version="2.4">
  7
  8 <filter>
  9     <filter-name>UrlRewriteFilter</filter-name>
 10     <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
 11 </filter>
 12 <filter-mapping>
 13     <filter-name>UrlRewriteFilter</filter-name>
 14     <url-pattern>/*</url-pattern>
 15     <dispatcher>REQUEST</dispatcher>
 16     <dispatcher>FORWARD</dispatcher>
 17 </filter-mapping>
 39 </web-app>

我还记得我还有一个例外。我修复了删除第一行之前的额外行

<?xml version="1.0" encoding="ISO-8859-1"?> 

来自我的 web.xml.