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

Asked

Viewed 142 times

0

I am studying JSF using the eclipse IDE, but am finding a certain problem when running my application. When I run the application by clicking on the project itself, it doesn’t seem to load my created template.

Following example:

inserir a descrição da imagem aqui

However, when I run by directly clicking on the page I want to display, the template loads correctly.

inserir a descrição da imagem aqui

index.xhtml

<ui:composition xmlns="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 I could be doing wrong?

1 answer

1


Note the right URL. In the first case you access the url http://localhost8080/Projeto and at the second moment http://localhost8080/Projeto/faces/index.xhtml. The difference becomes clear after this, in the first case you are accessing the page without going through the framework of JSF and in the second case it goes through the processing of the framework. If you want the page index.xhtml is 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>
  • 1

    I hadn’t noticed that detail faces. Thank you very much, Lucas.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.