What is the correct way to run a web application in eclipse?

0

I'm studying JSF using the eclipse IDE, but I'm encountering a certain problem when running my application. When I run the application by clicking on top of the project itself, it does not seem to load my created template.

Here's an example:

However,whenIexecutebyclickingdirectlyonthepagethatIwanttodisplay,thetemplateloadscorrectly.

index.xhtml

<ui:compositionxmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
template="/WEB-INF/templates/Layout.xhtml">

<ui:define name="content">Bem-Vindo</ui:define>

</ui:composition>

Layout.xhtml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets">

<h:head>
    <title>Log Horizon</title>
</h:head>

<h:body>
    <h1>Teste de Layout</h1>
    <hr />
    <ui:insert name="content"></ui:insert>
</h:body>
</html>

This happens in every project I create. What could I be doing wrong?

    
asked by anonymous 13.10.2018 / 23:19

1 answer

1

Look at the right URL. In the first case you access the url http://localhost8080/Projeto and in the second moment http://localhost8080/Projeto/faces/index.xhtml . The difference is clear after this, in the first case you are accessing the page without going through the JSF framework and in the second case it goes through the processing of the framework. If you want the index.xhtml page to be automatically processed by the framework configure your web.xml as follows:

<?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">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <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>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>
    
14.10.2018 / 00:03