Sponsered Links
Categories
Sponsered Links

JSF Hello World application

 

This is a simple JSF Hello World application.

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>
       HelloWorldJSF
    </display-name>
    
    <description>
       Hello in the JavaServer Faces World!
    </description>

    <listener>
        <listener-class>
            org.apache.myfaces.webapp.StartupServletContextListener
        </listener-class>
    </listener>
    
    <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>*.jsf</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
       <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
        
</web-app>

 

faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
                              "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config>

    <managed-bean>
       <managed-bean-name>helloWorldBean</managed-bean-name>
       <managed-bean-class>com.tutorial.HelloWorldBean</managed-bean-class>
       <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>

</faces-config>

 

HelloWorldBean.java

package com.tutorial;

public class HelloWorldBean {
    
    private String hello = "Hello in the JavaServer Faces World!";
    
    public String getHello () {
  return this.hello;
    }
}

 

helloworld.jsp

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<html>
<head>
    <title>HelloWorldJSF</title>
</head>
<body>
    <f:view>
  <h:form>
      <h3>
         <h:outputText value="#{helloWorldBean.hello}" />
      </h3>
  </h:form>
    </f:view>
</body>
</html>

 

index.jsp

<% response.sendRedirect("helloworld.jsf"); %>

 
 
Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2009 JSPSERVLETTUTORIAL.INFO All Right Reserved