I need to clarify this doubt. I hope you help me.
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<display-name>jsfdemo</display-name>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
Is that url-pattern (/faces/*) required to appear in all URLs in my app? I see some examples when deploying their demos if they are immediately shown a URL like this.
But it looks like this to me:
And if I add the /faces/ it shows me the JSF component:
Let's say everything looks like any newbie question and I may have done something wrong. But then I see projects like this:
That nowhere in the app does it use /faces/ in its URL. The truth is that I have already looked for something clear but I still cannot understand if it is going or not.
Plus: I just found one where it doesn't even put the /faces/ in the web.xml. I do not know what to think. Please help.
In that part of the web.xml that you comment on, you are declaring the url pattern that the servlet "Faces Servlet" will know how to interpret.
First, what is a servlet?
Well, a servlet is nothing more than a java class that knows how to listen to HTTP requests, such as a GET or a POST. Before frameworks such as Struts, Spring or JSF existed, Java developers created dynamic web applications using servlets, which were deployed in some servlet container (such as Tomcat, for example). As this was quite cumbersome or a lot of work had to be done, web frameworks were born, which do a lot of work for us and which are built on this Servlet technology. (In fact, if you look at your web.xml you are declaring a JSF servlet)
To answer your question, you can put whatever you want as url-pattern, what you declare there is what kind of urls the configured servlet will be listening to.