简体   繁体   中英

HTTP Status 404 - Building a JSF with Maven

So I am trying to do a tutorial in which I build with maven a project from cmd, then import it in eclipse, create a jsf with hello world message, but when i enter on http://localhost:8080/helloworld2/home.jsf i get the 404 not found error.

This is my HelloWorld class

import javax.faces.bean.ManagedBean;
@ManagedBean(name = "helloWorld", eager = true)
public class HelloWorld {
    public HelloWorld() {
        System.out.println("HelloWorld started!");
    }
    public String getMessage() {
        return "Hello World!";
    }
}

This is the home.xhtml :

   <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title>JSF Tutorial!</title>
        </head>
        <body>
            #{helloWorld.message}
        </body>
    </html>

I have deployed the .war file and then ran it on Tomcat. I may have not explained it very well, but any help is more than welcome. Thanks!

If your home.xhtml is on src>webapp

and your web.xml contains this should work

<!-- Welcome page -->
    <welcome-file-list>
        <welcome-file>faces/home.xhtml</welcome-file>
    </welcome-file-list>
        <!-- Map these files with JSF -->
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM