JSF (JavaServer Faces) Hello World Example Eclipse Tomcat




Hey guys in this post, we will create Java web application and print Hello World message using Java JSF.

Complete example


We will create this example step by step, follow this tutorial till the end

Create Dynamic Web Project


I will be using STS IDE for this tutorial. You can also use Eclipse or IntelliJ IDEA, the steps are pretty much same.

On the IDE, go to File -> New -> Choose Dynamic Web Project
00

Next, enter the following details such as Project name, Dynamic web module version and then click on the Modify option

01

Next, make sure to select the JavaServer Faces option and click Ok

02

Click next

03
Next, make sure to check the option for Generate web.xml deployment descriptor

04

Click next, choose the Type option to Disable Library Configuration and click finish to create the project

05

This will create the Project on the IDE, the structure of typical Dynamic Web Project that looks like this

06

Next download the JSF library (JAR) and add it to the lib folder inside the WebContent.

08

Download Link: https://maven.java.net/content/repositories/releases/org/glassfish/javax.faces/2.2.8/
09Next, create hello-world.xhtml file inside the WebContent folder and add the following content

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
		xmlns:h="http://xmlns.jcp.org/jsf/html">
	
	<h:head>
		<title>Hello World - Demo</title>
	</h:head>
	
	<h:body>
		
		<p>Hello World</p>
		
	</h:body>

</html>

At the top, we will reference to the JSF HTML components. We will specify the namespace at the top of the HTML document.

<html xmlns="http://www.w3.org/1999/xhtml"
		xmlns:h="http://xmlns.jcp.org/jsf/html">

Run the app


To run the application, right click on the project, select Run As -> choose Run on Server

10

Next, select tomcat server

11

Next, click Finish to start the tomcat server

12

Open the browser, navigate to the URL http://localhost:8080/JSF-hello-world/faces/hello-world.xhtml

07

By default, all the resources available at the URI mapping /faces/**

That’s it for this post. If you like this post, then please share this with your friends and collogues. Also share this post on your social media profiles as well.



Bushan Sirgur

Hey guys, I am Bushan Sirgur from Banglore, India. Currently, I am working as an Associate project in an IT company.

Leave a Reply