FacesServlet and URL Mapping in Web.xml

Hi

We are announcing FacesServletits URL in Web.xml. In my opinion,

FacesServletIt loads only once at server startup. URL mapping is used only the first time you access a JSP application from an external context.

One of the new JSF students asked me questions, these two things are used only once by the application. It's true? Also is there any other way, not including in web.xml?

What should I answer?

Update

For example, I access the application using the URL http://localhost:8080/webapp/index.jsf. When we access this URL, FacesServletinvoked and view is displayed . Here is my question:

  • In JSF, we never saw a URL change in the address bar. In this case, how does it handle a new request with the same URL?
  • In faces-config.xml we list the following navigation cases:

    to-view-id> failure.jsp / to-view-id>

    • Why don't we need to specify the view name as failure.jsf? We just point * .jsp to faces-config.xml. How is it processed internally?
+3
source share
2 answers

FacesServlet is loaded only once at server startup.

Correctly.

URL mapping is used only the first time you access a JSP application from an external context.

Wrong. He was tested on every incoming HttpServletRequest. How else should a container know which servlet should call?

Also is there any other way, not including in web.xml?

, Servlet 3.0, @WebServlet . JSF 2.0, , Servlet 2.5, , web.xml.

. :


( , ala)

JSF URL- . , URL-?

, RequestDispatcher#forward(). , servletcontainer HTTP-/ ( JSP/XHTML). / - . , HttpServletResponse#sendRedirect() (-) new GET , , URL- . JSF, <redirect/> <navigation-case>. , , beans .

fail.jsf? *.jsp faces-config.xml. ?

FacesServlet url-pattern.

+3

. web.xml

URL . , , , , , , , doGet() doPost() .

URL- JAVAEE-6

-

import javax.servlet.annotation.InitParam;
import javax.servlet.annotation.WebServlet;

@WebServlet(
    name = "SimpleServlet", 
    urlPatterns = {"/login"}, 
    initParams = {
        @InitParam(name = "param1", value = "value1"),
        @InitParam(name = "param2", value = "value2")}
)
public class SimpleServlet {
}

faces-config.xml :

<to-view-id>failure.jsp </to-view-id>

fail.jsf? *.jsp faces-config.xml. ?

view identifier URL FacesServlet .

+2

Source: https://habr.com/ru/post/1788231/


All Articles