本文說明如何架設起一個ZK Framework 專案。
一、環境
1. JDK 1.7
2. TOMCAT 7.0
3. IDE - eclipse(已安裝完成zk studo)(如果沒有安裝時請參考ZK Studio 安裝 for Eclipse)
二、專案架構 - Maven
三、ZK專案所需要的套件 - pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.puma.zk.sample</groupId> <artifactId>zkSample-1</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <properties> <zk.version>8.0.1.1</zk.version> </properties> <dependencies> <dependency> <groupId>org.zkoss.zk</groupId> <artifactId>zk</artifactId> <version>${zk.version}</version> </dependency> <dependency> <groupId>org.zkoss.zk</groupId> <artifactId>zhtml</artifactId> <version>${zk.version}</version> </dependency> <dependency> <groupId>org.zkoss.zk</groupId> <artifactId>zul</artifactId> <version>${zk.version}</version> </dependency> <dependency> <groupId>org.zkoss.common</groupId> <artifactId>zcommon</artifactId> <version>${zk.version}</version> </dependency> <dependency> <groupId>org.zkoss.common</groupId> <artifactId>zweb</artifactId> <version>${zk.version}</version> </dependency> <dependency> <groupId>org.zkoss.common</groupId> <artifactId>zel</artifactId> <version>${zk.version}</version> </dependency> <dependency> <groupId>org.zkoss.zk</groupId> <artifactId>zkbind</artifactId> <version>${zk.version}</version> </dependency> </dependencies> </project>
四、web.xml設定
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <display-name>zkSample-1</display-name> <listener> <description>Used to cleanup when a session is destroyed</description> <display-name>ZK Session cleaner</display-name> <listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class> </listener> <servlet> <!-- 處理有關http頁面所請求的類別(包含ajax) --> <description>The ZK loader for ZUML pages</description> <servlet-name>zkLoader</servlet-name> <servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class> <!-- 非同步更新url位置 --> <init-param> <param-name>update-uri</param-name> <param-value>/zkau/*</param-value> </init-param> <!-- 如果瀏覽器支持壓縮並且當前servlet沒有被其他servlet包含時,是否壓縮輸出 --> <init-param> <param-name>compress</param-name> <param-value>true</param-value> </init-param> <!-- zk log 級別 --> <init-param> <param-name>log-level</param-name> <param-value>OFF</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet> <!-- 負責處理zk 的事件請求 --> <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>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-mapping> <servlet-name>auEngine</servlet-name> <url-pattern>/zkau/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> <welcome-file>index.zul</welcome-file> </welcome-file-list> </web-app>
五、顯示頁面hrllo.zul
<window title="My First ZK Application" border="normal"> Hello World! </window>
六、啟動tomcat即可顯示結果
其它文章
沒有留言:
張貼留言