Hey guys in this post, we will create Java web application and print Hello World message using Java JSF.
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.
Next, enter the following details such as Project name, Dynamic web module version and then click on the Modify option
Next, make sure to select the JavaServer Faces option and click Ok
Click next, choose the Type option to Disable Library Configuration and click finish to create the project
This will create the Project on the IDE, the structure of typical Dynamic Web Project that looks like this
Next download the JSF library (JAR) and add it to the lib folder inside the WebContent.
Download Link: https://maven.java.net/content/repositories/releases/org/glassfish/javax.faces/2.2.8/
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
Next, select tomcat server
Next, click Finish to start the tomcat server
Open the browser, navigate to the URL
By default, all the resources available at the URI mapping
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.