What is the use of adding / faces / in the web.xml?

0

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 / *) mandatory to appear in all the URLs of my application? I see some examples when displaying your demos if they are immediately shown such a URL.

But it looks like this:

And if I add the / faces / it shows me the JSF component:

Let's say everything looks like novice questions and something I could have done wrong. But then I see projects like this:

That nowhere in the application uses the / faces / in its URL. The truth and I looked for something clear but I still can not understand if it goes or not going.

Plus: I just found one where you do not put the / faces / in the web.xml. I do not know what to think. Help please.

    
asked by Hector Ccasani PerdidaMente 05.06.2018 в 18:31
source

1 answer

1

In that part of the web.xml that you are commenting on, declaring what is the url pattern that the servlet "Faces Servlet" will interpret.

First, what is a servelt?

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 like Struts, Spring or JSF existed, Java developers created dynamic web applications using servlets, which were deployed in a servlet container (such as Tomcat, for example). As this was quite cumbersome or had to do a lot of work, 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)

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

To answer your question, you can put what you want as a url-pattern, what you say there is what type of url's going to be listening to the configured servlet.

    
answered by 06.06.2018 / 02:25
source