Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从web.xml中排除特定路径?_Java_Servlets_Xrebel - Fatal编程技术网

Java 如何从web.xml中排除特定路径?

Java 如何从web.xml中排除特定路径?,java,servlets,xrebel,Java,Servlets,Xrebel,我有以下配置: <servlet-mapping> <servlet-name>RestletServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <

我有以下配置:

<servlet-mapping>
    <servlet-name>RestletServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>

RestletServlet
/*
index.html
我需要排除“
/xrebel
”,因为Restlet正在捕获此路径,并且无法访问xrebel。但是,我需要将
url模式保持为
/*


如何才能访问这样的
/xrebel
路径

去年我在开发Web服务时遇到了同样的问题。但是在做了大量的研究之后,我发现这个问题没有简单易行的解决方案

相反,我发现最好的方法是使用前缀servlet URL

因此,对于希望由RestletServlet处理的所有映射,请向url添加一个前缀,例如/rest/*


希望这能有所帮助。

一个可能的解决方案是创建一个具有相同url模式的筛选器来拦截请求

在过滤器中,您可以检查模式是否等于
/xrebel
,然后根据需要处理请求

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    String requri = ((HttpServletRequest) request).getRequestURI().substring(((HttpServletRequest) request).getContextPath().length() + 1);
    System.out.println(requri);
    if(requri.equals("/xrebel")){

    //do something else

    }else{
       chain.doFilter(request, response);   //continue normally
      }
}