ajax框架之zk实例收藏
<script type="text/javascript">function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}</script> 前 一段在网上看查找资料,无意间发现了一个 ajax框架的在线demo,被其华美的外表及简洁的代码风格所吸引,就开始了zk学习之路,经过两天的研究,发现这个框架确实不错,特别是它提供的例 子,基本实现了所有web开发的需要,它还对google map进行了封装,使其使用更加容易,不过,经这两天的学习,发现它的学习资料不是太多,找好长时间也找不到多少有用的,只好研究它自带的demo了,呵 呵,一段时间的研究,终于写出了一个小实例,现在提供出来,希望能对大家有帮助。该实例在 eclipse3.2+myeclipse+tomcat5.5+jdk5.0上运行成功。 欢迎转载,有问题请联系我:txyhl@126.com 首先,为了让大家对其有一个感性的认识,就先去看看它的demo,相信你也会被它华美的外表所吸引
![](http://blog.csdn.net/Editor/FCKeditor/editor/images/smiley/msn/teeth_smile.gif)
<?
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"
>
<
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
>
<
filter
>
<
filter-name
>
zkFilter
</
filter-name
>
<
filter-class
>
org.zkoss.zk.ui.http.DHtmlLayoutFilter
</
filter-class
>
<
init-param
>
<
param-name
>
extension
</
param-name
>
<
param-value
>
html
</
param-value
>
<!--
Use XHTML components as default.
-->
</
init-param
>
</
filter
>
<
filter-mapping
>
<
filter-name
>
zkFilter
</
filter-name
>
<
url-pattern
>
*.jsp
</
url-pattern
>
<
dispatcher
>
REQUEST
</
dispatcher
>
<
dispatcher
>
INCLUDE
</
dispatcher
>
<
dispatcher
>
FORWARD
</
dispatcher
>
<
dispatcher
>
ERROR
</
dispatcher
>
</
filter-mapping
>
<
servlet
>
<
description
>
ZK loader for ZUML pages
</
description
>
<
servlet-name
>
zkLoader
</
servlet-name
>
<
servlet-class
>
org.zkoss.zk.ui.http.DHtmlLayoutServlet
</
servlet-class
>
<!--
Must. Specifies URI of the update engine (DHtmlUpdateServlet). It must be the same as <url-pattern> for the update engine.
-->
<
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
>
<!--
-->
<!--
///
-->
<!--
Miscellaneous
-->
<
session-config
>
<
session-timeout
>
120
</
session-timeout
>
</
session-config
>
<
welcome-file-list
>
<
welcome-file
>
index.zul
</
welcome-file
>
</
welcome-file-list
>
</
web-app
>
<
window
title
="yhltest demo"
border
="normal"
>
<
zscript
>
{ //引入Test类 import test.*; void submit() { Test test = new Test(); //调用Test类的方法getTestStr,并将返回值赋给mylabel mylabel.value=test.getTestStr(text1.value); } }
</
zscript
>
<
grid
>
<
rows
>
<
row
><
label
id
="mylabel"
value
="test"
/></
row
> //输入1 或 2
<
row
>
input(1or2)
<
textbox
id
="text1"
/></
row
> //提交,调用函数submit
<
row
><
button
label
="submit"
onClick
="submit()"
/></
row
>
</
rows
>
</
grid
>
</
window
>
package
test;
public
class
Test {
public
String getTestStr(String flag) {
if
(flag.equals(
"
1
"
)) {
return
this
.getTestStr1(); }
else
if
(flag.equals(
"
2
"
)) {
return
this
.getTestStr2(); }
else
{
return
"
请输入正确的参数
"
; } }
public
String getTestStr1() {
return
"
调用类Test的getTestStr1方法
"
; }
public
String getTestStr2() {
return
"
调用类Test的getTestStr2方法
"
; } }
编写工作到此完成。 将其发布到tomcat下面,然后在浏览器中输入:http://localhost:8080/zktest/即可测试该功能。 现在jsp和zk页的整合还没有研究出来,希望有过这方面开发经验的大虾指点一二,可以用邮箱和我联系。