Tomcat

From Documentation


Install Tomcat

  • First, visit http://tomcat.apache.org/download-60.cgi
  • Second, select the correct binary distribution for your environment.
    • Windows users could select "32-bit/64-bit Windows Service Installer" and then follow its instructions.

Test drive with the ZK demo application

The simplest way to test drive ZK is to download and install the ZK demo application.

This step is optional. You could skip it if you prefer to start creating your own application directly.

  1. Download at http://sourceforge.net/projects/zk1/files/ZK/zk-5.0.4/zk-demo-5.0.4.zip/download[1]
  2. Unzip zk-demo-5.0.4.zip
  3. Copy zkdemo.war under the zk-demo-5.0.4 directory to $TOMCAT_HOME/webapps. $TOMCAT_HOME is the directory you installed Tomcat, for example, C:\Program Files\Apache Software Foundation\Tomcat 6.0.
  4. Then, you could visit http://localhost:8080/zkdemo, and then play around with the demo application

  1. It is recommended to visit http://www.zkoss.org/download/zk.dsp for the most updated version.

Create your first application

Here is how to create a Web application manually without IDE or other tools. It is easy to find the similar procedure with your preferred IDE or tools, such as Eclipse and NetBeans.

Download ZK

First, download the ZK libraries from http://www.zkoss.org/download/zk.dsp and save it to a proper location.

Create a Web application

Creating a Web application in Tomcat is easy: just create a directory under $TOMCAT_HOME/webapps. $TOMCAT_HOME is the directory you installed Tomcat, for example, C:\Program Files\Apache Software Foundation\Tomcat 6.0.

Let us assume the application is called myZK. Then, the directory structure shall be as follows.

myZK
WEB-INF
WEB-INF/lib

Deploy ZK libraries

  1. Unzip zk-bin-5.0.4.zip
  2. Copy JAR files under dist/lib to $TOMCAT_HOME/webapps/myZK/WEB-INF/lib

Create web.xml

Create web.xml under $TOMCAT_HOME/webapps/myZK/WEB-INF, and Copy the following content into web.xml.

Notice that the ZK demo distribution has two web.xml files under the MyApp/WebContent/WEB-INF directory: web.xml (for servers supporting Servlet 2.4 or later), and web.servlet-2.3.xml (for servers supporting only Servlet 2.3). You could copy one of them instead of creating from scratch.

<syntax lang="xml"> <?xml version="1.0" encoding="UTF-8"?>

<web-app 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"> 

<description><![CDATA[My ZK Application]]></description> <display-name>MyApp</display-name>

<listener> <description>ZK listener for session cleanup</description> <listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class> </listener> <servlet> <description>ZK loader for ZUML pages</description> <servlet-name>zkLoader</servlet-name> <servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>

<init-param> <param-name>update-uri</param-name> <param-value>/zkau</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>zkLoader</servlet-name> <url-pattern>*.zul</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>zkLoader</servlet-name> <url-pattern>*.zhtml</url-pattern> </servlet-mapping> <servlet> <description>The asynchronous update engine for ZK</description> <servlet-name>auEngine</servlet-name> <servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>auEngine</servlet-name> <url-pattern>/zkau/*</url-pattern> </servlet-mapping>

<welcome-file-list> <welcome-file>index.zul</welcome-file> <welcome-file>index.zhtml</welcome-file> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> </welcome-file-list> </web-app> </syntax>

Create your application

After setting up web.xml, it is ready to serve your application.

For example, we can create a simple page, say, hello.zul with the following content.

<syntax lang="xml">

<window title="My First ZK Application" border="normal">
	Hello World!
</window>

</syntax>

Then, you can see the result by visiting http://localhost:8080/myZK/hello.zul[1].

DgGettingStartedHello.zul.png


  1. Assumes Tomcat's port is 8080 and started.

Version History

Version Date Content
     



Last Update : 2010/09/06

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.