Tuckey UrlRewrite:更改urlrewrite.xml后的ClassNotFoundException

时间:2015-02-24 23:38:05

标签: java tomcat tomcat7 tuckey-urlrewrite-filter urlrewriter

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

我正在运行Tomcat 7.在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 $ 1.run(URLClassLoader.java:366)at   java.net.URLClassLoader $ 1.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)     在   org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)     在   org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:145)     在   org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:172)     在   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)     在   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)     在org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:727)at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)     在   org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)     在   org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)     在   org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:389)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)     在   org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486)     在   org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411)     在   org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)     在   org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:213)     在   org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:171)     在   org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)     在   org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)     在   org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:389)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   au.com.pawsforlife.vizsla.controller.UserFilter.doFilter(UserFilter.java:81)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)     在   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)     在   org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)     在   org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)     在   org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:611)     在   org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:314)     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:615)     在   org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)     在java.lang.Thread.run(Thread.java:745)

有谁知道为什么会这样,或至少如何解决?

谢谢!

2 个答案:

答案 0 :(得分:4)

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

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

他们有一个simple rule的例子。

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

答案 1 :(得分:3)

我过去也有类似的例外,但我不记得细节。这就是我从一个简单的项目中分享我的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/$1</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。