Downloading and Installing NetBeans IDE
9. Developing and Deploying Web Application in NetBeans
9.5. Writing a Hello-world JSF 1.2 Web Application
Create a New JSF 1.2 Project
- From "File" menu ⇒ choose "New Project...".
- "Choose Project" ⇒ In "Categories", choose "Java Web" ⇒ In "Projects", choose "Web Application" ⇒ "Next".
- "Name and Location" ⇒ In "Project Name", enter "
HelloJSF12
" ⇒ In "Project Location", select a suitable directory to save your works ⇒ Check "Set as Main Project" ⇒ Next. - "Server and settings" ⇒ choose your server, or "add" a new server ⇒ Next.
- "Frameworks" ⇒ Check "JavaServer Faces" ⇒ In "Libraries", "Registered Libraries", select "JSF 1.2" ⇒ Finish.
- A "
WelcomeJSF.jsp
" page is generated, as follows:<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%> <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%> <!DOCTYPE html> <%-- This file is an entry point for JavaServer Faces application. --%> <f:view> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>JSP Page</title> </head> <body> <h1><h:outputText value="JavaServer Faces"/></h1> </body> </html> </f:view>
To run this page, right-click on the project ⇒ Run.
Create a new JSF 1.2 Page
- Right-click on the project ⇒ New ⇒ "Other..."
- "Choose File Type" ⇒ In "Category", select "JavaServer Faces" ⇒ In "File Type", select "JSF Page" ⇒ Next.
- "Name and Location" ⇒ In "File Name", enter "
HelloJSF12
" ⇒ In "Options", check "JSP File (Standard Syntax)" ⇒ Finish. - In "
HelloJSF12.jsp
", enter the following codes:<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%> <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%> <!DOCTYPE html> <f:view> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>Hello JSF 1.2</title> </head> <body> <h1><h:outputText value="Hello World!"/></h1> </body> </html> </f:view>
-
To execute the JSF page, right-click on the project ⇒ Run ⇒ Change the URL to
http://localhost:8080/HelloJSF12/faces/HelloJSF12.jsp
.