Url rewriting URL重写筛选器错误

Url rewriting URL重写筛选器错误,url-rewriting,servlet-filters,Url Rewriting,Servlet Filters,我正在使用maven,并将urlrewrite.xml放在源文件夹src/main/resources/下。按如下方式配置web.xml: <filter> <filter-name>UrlRewriteFilter</filter-name> <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class> <init-param>

我正在使用maven,并将urlrewrite.xml放在源文件夹src/main/resources/下。按如下方式配置web.xml:

<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
    <param-name>confPath</param-name> 
    <param-value>classpath:urlrewrite.xml</param-value>             
</init-param>


</filter>

  <filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
  </filter-mapping>

URL重写过滤器
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter
confPath
类路径:urlrewrite.xml
URL重写过滤器
/*
要求
向前地
但是获取错误:org.tuckey.web.filters.urlrewrite.UrlRewriteFilter错误:无法在类路径:urlrewrite.xml中找到urlrewrite conf文件。如果我把它放在默认位置:/WEB-INF/URLRewite.xml。它起作用了。但我希望符合maven规范,并将所有配置放在resources文件夹下

谁能帮我一下吗?谢谢。

用这个

<init-param>
    <param-name>confPath</param-name>
    <param-value>/WEB-INF/urlrewrite.xml</param-value>
</init-param>

confPath
/WEB-INF/urlrewrite.xml
并将urlrewrite.xml文件放入“WEB-INF”中
有安装说明。

不是世界上最干净的解决方案,但我找到了解决办法。请注意,我的应用程序是基于spring的:

公共类增强DurlRewriteFilter扩展了UrlRewriteFilter{

private String confPath;

private final Log logger = LogFactory.getLog (getClass ());

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    String confPathStr = filterConfig.getInitParameter("confPath");
    confPath = StringUtils.trim(confPathStr);
    super.init (filterConfig);
}

@Override
protected void loadUrlRewriter (FilterConfig aFilterConfig) throws ServletException {

    try {  
        configure (aFilterConfig.getServletContext ());
    }
    catch (Throwable e) {
        throw new IllegalArgumentException (e);
    }

}

private void configure (ServletContext context) throws IOException {

    ResourceLoader webApplicationContext = WebApplicationContextUtils.getWebApplicationContext (context);

    Resource resource = webApplicationContext.getResource (confPath);

    logger.debug ("Loaded urlrewrite.xml from " + resource.getFilename ());

    InputStream inputStream = resource.getInputStream();

    URL confUrl = null;

    try {
        confUrl = context.getResource(confPath);
    } catch (MalformedURLException e) {
        logger.debug(e);
    }

    String confUrlStr = null;
    if (confUrl != null) {
        confUrlStr = confUrl.toString();
    }

    if (inputStream != null) {
        Conf conf = new Conf(context, inputStream, confPath, confUrlStr, false);
        checkConf(conf);
    }
}
}

在my web.xml中:

<filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>EnhancedUrlRewriteFilter</filter-class>
    <init-param>
        <param-name>confPath</param-name>
        <param-value>classpath:urlrewrite.xml</param-value>
    </init-param>
    <init-param>
        <param-name>logLevel</param-name>
        <param-value>WARN</param-value>
    </init-param>
</filter>

URL重写过滤器
EnhancedUrlRewriteFilter
confPath
类路径:urlrewrite.xml
对数电平
警告

我可以把它放在其他地方吗?那么confPath参数的用途是什么呢?我发现这个问题是根据他们的说法解决的,首先过滤器尝试从servlet上下文加载它。如果找不到,它会尝试从系统的类加载器加载它。我明白了。我试图通过实现自己的URLEwriteFilter来解决这个问题,但它似乎有太多的依赖性。所以我放弃了。我将不得不使用上下文路径。非常感谢。