Tags

Installing JSF 1.2 on the latest apache-tomcatAnd test a Hello World type application 

Download

To run JSF 1.2, you would require Servlet 2.5 and JSP 2.1 compliant container. So we will install Tomcat 6.0 or above. We will also install the JSTL because JSF development requires it.

So what we need:

1.      apache-tomcat-6.0 or up (http://tomcat.apache.org/download-60.cgi)

2.      JSF 1.2 (https://javaserverfaces.dev.java.net/files/documents/1866/87641/mojarra-1.2_08-FCS-binary.zip)

3.      JSTL (http://jakarta.apache.org/site/downloads/downloads_taglibs-standard.cgi)

Install

Step 1. Extract the downloaded zip file (apache-tomcat-6.0 or up) under the C:\ root folder.

Step 2. Create folders related to test our JSF installation or more precisely JSF web application

a)      Create a directory jsftest under c:\apache-tomcat-6.0\webapps

b)      Create a directory called WEB-INF under c:\apache-tomcat-6.0\webapps\jsftest

c)      Create directories called “classes” and “lib” under c:\apache-tomcat-6.0\webapps\jsftest\WEB-INF

d)      Create a file called web.xml under c:\apache-tomcat-6.0\webapps\jsftest\WEB-INF with following content

<?xml version=’1.0′ encoding=’UTF-8′?>

<!DOCTYPE web-app PUBLIC

“-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN”

“http://java.sun.com/dtd/web-app_2_3.dtd”>

<web-app>

      <!– Faces Servlet –>

      <!– We are defining the Faces Servlet here –>

      <servlet>

      <servlet-name>Faces Servlet</servlet-name>

      <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>

      <load-on-startup> 1 </load-on-startup>

      </servlet>

      <!– Faces Servlet Mapping –>

<!–All requests with .jsf will be mapped Faces Servlet –>

      <servlet-mapping>

      <servlet-name>Faces Servlet</servlet-name>

      <url-pattern>*.jsf</url-pattern>

      </servlet-mapping>

</web-app>

e)      Create a JSF specific file called faces-config.xml under c:\apache-tomcat-6.0\webapps\jsftest\WEB-INF and copy paste the following for now

<?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>

</faces-config>

Step 3. Extract the downloaded JSF zip file (mojarra-1.2_08-FCS-binary.zip) into some temp or whatever folder you prefer. After extracting, copy the following jars into c:\apache-tomcat-6.0\webapps\jsftest\WEB-INF\lib

a)      jsf-api.jar

b)      jsf-impl.jar

Step 4. Extract the downloaded JSTL zip file (mojarra-1.2_08-FCS-binary.zip) into some temp or whatever folder you prefer. After extracting, copy the following jars into c:\apache-tomcat-6.0\webapps\jsftest\WEB-INF\lib

a)      jstl.jar

b)      standard.jar

A little more on Step 3 and Step 4: Of course one way to make jars available to a web application is to place them into WEB-INF\lib folder of the web application. If you have several web applications and they all want to use some common jars, you can put the jar files into a common location and that common location for Tomcat is c:\apache-tomcat-6.0\common\lib. Important thing to remember is if you copy the JAR files into the common directory while the server is running, you may need to restart the Tomcat server so the new JAR files can be loaded.

Step 5. Create an index.jsp file and save it under c:\apache-tomcat-6.0\webapps\jsftest directory and type the following

<jsp:forward page=”test.jsf”/> <%– this would just forward the request to test.jsf –%>

Step 6. Create a test.jsf under the same directory (c:\apache-tomcat-6.0\webapps\jsftest) and type the following content

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>

<%@page language=”java” contentType=”text/html; charset=ISO-8859-1″ pageEncoding=”ISO-8859-1″%>

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

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

<html>

<head>

            <title>register</title>

</head>

<f:view>

            <body>

           

                        <h:outputText value=”JSF page loaded successfully!”/>

           

            </body>

</f:view>

</html>

Step 7. To test the jsf page (and the application), start tomcat and then type in http://localhost:8080/jsftest/

Your browser would show a page saying

JSF page loaded successfully!

DONE! 

Extra:

Running Tomcat 6 with Eclipse and JSF

http://www.crazysquirrel.com/computing/java/jsf/eclipse-with-tomcat-6-and-jsf-1-2.jspx

Advertisements