Parsing URL Filter URLs
I have below view of filter displaying my web xml. But the deployment fails. Is there any alternative? thank
<filter-mapping>
<filter-name>TestFilter</filter-name>
<url-pattern>*.js</url-pattern>
</filter-mapping> <!-- this works -->
<filter-mapping>
<filter-name>TestFilter</filter-name>
<url-pattern>/Application/*.html</url-pattern>
</filter-mapping> <!-- this doesn't work with parsing error as below-->
Mistake
java.lang.IllegalArgumentException: Invalid URL Pattern: [{0}]
at org.glassfish.web.deployment.node.WebResourceCollectionNode.setElementValue(WebResourceCollectionNode.java:136)
at com.sun.enterprise.deployment.node.SaxParserHandler.endElement(SaxParserHandler.java:583)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:609)
+3
source to share
1 answer
I am afraid that the mixing by suffix and prefix matching, as in /Application/*.html
, is not supported. You need to match one of the following patterns:
-
/Application/*
(everything with a prefix/Application
will be displayed) -
/*.html
(all with a suffixhtml
will be displayed)
If you want to combine them together, you can match the prefix (first option) with a proxy servlet that will parse the url in the request and redirect it to the appropriate servlet using ServletContext.html # getNamedDispatcher and forward(req, resp)
like this for a servlet named application-html
:
if (request.getRequestURI().endsWith(".html")) {
request.getServletContext()
.getNamedDispatcher("application-html")
.forward(request, response)
}
+1
source to share