Hi Jasmine,
I am very new to tomcat and I don't know what changes I need to make
in web.xml for the "jsfks" application or server.xml in config directory.
Does the server.xml
need a new Context entry for the "jsfks" application?
Thank you so much for any suggestions you can give me.
BL
Here's the directory structure of the
JSF under tomcat:
webapps
|->jsfks
|->
ant - contains build.xml
|->JavaSource
|->bundle - contains Message.properties
|
|->jsfks - contains PersonBean.java
|
|->WebContent
|->pages - contains greeting.jsp, index.jsp and inputname.jsp
|
|->WEB-INF - contains web.xml and faces-config.xml
|->classes
| |->bundle - contains Message.properties
| |
| |->jsfks - contains PersonBean.class
|
|->lib - contains commons-beanutils.jar,commons-collections.jar,commons-digester.jar
commons-logging.jar, jsf-api.jar, jsp-impl.jar, jsf-ri.jar, jstl.jar,
standard.jar
====================================================================
web.xml:
<?xml version="1.0"?>
<!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>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.faces.application.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<!-- Faces
Servlet -->
<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 -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
</web-app>
==================================================================
faces-config.xml:
<?xml version="1.0"?>
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
"http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
<faces-config>
<navigation-rule>
<from-view-id>/pages/inputname.jsp</from-view-id>
<navigation-case>
<to-view-id>/pages/greeting.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<description>
Input Value Holder
</description>
<managed-bean-name>GetNameBean</managed-bean-name>
<managed-bean-class>demo.GetNameBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>userName</property-name>
<property-class>java.lang.String</property-class>
<value></value>
</managed-property>
</managed-bean>
</faces-config>
===============================================================================
build.xml:
roject name="jsjks" basedir="../" default="deploy">
<!-- Project settings -->
<property name="project.distname" value="jsfks"/>
<!-- define your folder for deployment -->
<property name="deploy.dir" value="deploy"/>
<!-- Local system paths -->
<property file="${basedir}/ant/build.properties"/>
<property name="webroot.dir" value="${basedir}/WebContent"/>
<property name="webinf.dir" value="${webroot.dir}/WEB-INF"/>
<property name="build.dir" value="build"/>
<!-- classpath -->
<path id="compile.classpath">
<pathelement path ="${webinf.dir}/lib/jsf-api.jar"/>
<pathelement path ="${webinf.dir}/lib/jsf-impl.jar"/>
<pathelement path ="${classpath}"/>
</path>
<!-- Check timestamp on files -->
<target name="prepare">
<tstamp/>
</target>
<!-- Copy any resource or configuration files -->
<target name="resources">
<copy todir="${webinf.dir}/classes" includeEmptyDirs="no">
<fileset dir="JavaSource">
<patternset>
<include name="**/*.conf"/>
<include name="**/*.properties"/>
<include name="**/*.xml"/>
</patternset>
</fileset>
</copy>
</target>
<!-- Normal build of application -->
<target name="compile" depends="prepare,resources">
<javac srcdir="JavaSource" destdir="${webinf.dir}/classes">
<classpath refid="compile.classpath"/>
</javac>
</target>
<!-- Remove classes directory for clean build -->
<target name="clean"
description="Prepare for clean build">
<delete dir="${webinf.dir}/classes"/>
<mkdir dir="${webinf.dir}/classes"/>
</target>
<!-- Build entire project -->
<target name="build" depends="prepare,compile"/>
<target name="rebuild" depends="clean,prepare,compile"/>
<!-- Create binary distribution -->
<target name="war" depends="build">
<mkdir dir="${build.dir}"/>
<war
basedir="${webroot.dir}"
warfile="${build.dir}/${project.distname}.war"
webxml="${webinf.dir}/web.xml">
<exclude name="WEB-INF/${build.dir}/**"/>
<exclude name="WEB-INF/src/**"/>
<exclude name="WEB-INF/web.xml"/>
</war>
</target>
<target name="deploy" depends="war">
<delete file="${deploy.dir}/${project.distname}.war"/>
<delete dir="${deploy.dir}/${project.distname}"/>
<copy file="${build.dir}/${project.distname}.war" todir="${deploy.dir}"/>
</target>
</project>
===============================================================================
Messages.properties:
inputname_header=JSF KickStart
prompt=Tell us your name:
greeting_text=Welcome to JSF
===============================================================================
PersonBean.java:
package jsfks;
public class PersonBean {
String userName;
/**
* @return User Name
*/
public String getUserName() {
return userName;
}
/**
* @param User Name
*/
public void setUserName(String name) {
userName = name;
}
}
===============================================================================
greeting.jsp:
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<f:loadBundle basename="bundle.Messages" var="Message"/>
<html>
<head> <title>Greeting Page</title> </head>
<body>
<f:view>
<h3>
<h utputText value="#{Message.greeting_text}" />,
<h utputText value="#{PersonBean.userName}" />!
</h3>
</f:view>
</body>
</HTML>
===============================================================================
index.jsp:
<html>
<body>
<
jsp:forward page="faces/pages/inputname.jsp" />
</body>
</html>
===============================================================================
inputname.jsp:
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<f:loadBundle basename="bundle.Messages" var="Message"/>
<HTML>
<HEAD> <title>Input Name Page</title> </HEAD>
<body>
<f:view>
<h1><h utputText value="#{Message.inputname_header}"/></h1>
<h:messages style="color: blue"/>
<h:form id="helloForm">
<h utputText value="#{Message.prompt}"/>
<h:inputText id="userName" value="#{PersonBean.userName}" required="true">
<f:validateLength minimum="2" maximum="10"/>
</h:inputText>
<h:commandButton id="submit" action="sayhello" value="Say Hello" />
</h:form>
</f:view>
</HTML>