Mapping a servlet to serve my requests

I would like to render a servlet to serve requests that include an "application" and ends in * .html as follows.

<url-pattern>/app/*.html</url-pattern>

but when the application starts, it causes an error

java.lang.IllegalArgumentException: Invalid <url-pattern> 
/app/*.html in servlet mapping

please help me display this. And please provide me with links where I can learn about this rule and URL mapping rules.

+5
source share
2 answers

This is really wrong. The wildcard must be the first or last character indicating the suffix or prefix, respectively.

<url-pattern>*.html</url-pattern>

or

<url-pattern>/app/*</url-pattern>

All of this is clearly indicated in Section 12.2 Servlet API Specification . Here's an excerpt of relevance:

12.2 Mapping specification

- :

  • , ‘/’ ‘/*’, .
  • , ‘*.’, .
  • ("") - URL, , http://host:port/<contextroot>/. ’/’, ("").
  • , ’/’, "" . URI null.
  • .

, 2 :

  • /app/* HTML /app. .

  • , /controller/*, Filter, /app/* doFilter():

    String uri = ((HttpServletRequest) request).getRequestURI();
    if (uri.endsWith(".html")) {
        request.getRequestDispatcher("/controller" + uri).forward(request, response);
    } else {
        chain.doFilter(request, response);
    }
    

:

+11

? /- ? , , /app .

0

All Articles