ZK的一些基础及总结(三)

本文介绍了如何在ZK框架中获取ServletContext和ApplicationContext,以及如何设置会话超时时间和超时后的跳转页面。通过XML配置文件可以灵活地调整这些设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

从本章开始介绍一些常用的方法及组件

 

获得ServletContext

java类中:getDesktop().getWebApp().getNativeContext()

当然,这个类要继承zk的某个组件才行,例如Window

zul中:desktop.getWebApp().getNativeContext()

有了他,获得ApplicationContext就不在话下了:

ApplicationContext ctx = 
			WebApplicationContextUtils.getRequiredWebApplicationContext(
				(ServletContext)getDesktop().getWebApp().getNativeContext());

 

zk的timeout

在WEB-INF/zk.xml中加入下边代码:

<session-config>
		<!-- 设置session过期时间,注意单位是秒-->
		<session-timeout>1800</session-timeout>
		
		<!-- Turn on the following if you want to reset the session-timeout
		counter when receiving onTimer, like any other request
		In other words, the session is never timeoout if the desktop has
		a timer.-->
<!-- 上边的注释我翻译不好,我一般是注释掉的 -->
		<!--<timer-keep-alive>true</timer-keep-alive>-->
		
</session-config>

<device-config>
		<device-type>ajax</device-type>
<!-- 设置timeout后跳转的页面 -->
		<timeout-uri>/timeout.zul</timeout-uri>
	</device-config>

 

 

下边转一个我在别的论坛看到的zk总结,比我总结的好多了!

原文地址:http://www.javaworld.com.tw/jute/post/view?bid=49&id=180896&tpg=1&ppg=1&sty=0&age=0

作者: rcblrcbl

原图放在附件里了

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值