Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why FacesServlet cannot have a url-pattern of /*.?

This is my web.xml :

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

When I navigate to:

http://localhost:8080/LearningRoot/index.xhtml

I can see the page just fine, however when I navigate to:

http://localhost:8080/LearningRoot/

I get the error:

An Error Occurred:

The FacesServlet cannot have a url-pattern of /*. Please define a different url-pattern.

But why?

And this is my welcome file:

<welcome-file-list>
    <welcome-file>/index.xhtml</welcome-file>
</welcome-file-list>
like image 427
Koray Tugay Avatar asked Mar 04 '13 20:03

Koray Tugay


People also ask

What does /* mean in URL pattern?

URL patterns use an extremely simple syntax. Every character in a pattern must match the corresponding character in the URL path exactly, with two exceptions. At the end of a pattern, /* matches any sequence of characters from that point forward.

What is the use of URL pattern in Web XML?

Servlets and URL Paths xml defines mappings between URL paths and the servlets that handle requests with those paths. The web server uses this configuration to identify the servlet to handle a given request and call the class method that corresponds to the request method (e.g. the doGet() method for HTTP GET requests).


1 Answers

Because that would mean Everything that ever hits that context-root will be handled by FacesServlet, a requirement that FacesServlet already knows it couldn't possibly fulfill (It obviously doesn't make sense).

To achieve the mapping you intend, use a .xhtml mapping on FaceServlet

<servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
like image 86
kolossus Avatar answered Sep 28 '22 10:09

kolossus