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

本文介绍了如何在ZK框架中获取ServletContext及ApplicationContext,并详细展示了如何配置会话超时及跳转页面,适用于需要理解ZK框架核心配置的开发者。

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

获得ServletContext

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

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

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

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

Java代码 复制代码
  1. ApplicationContext ctx =    
  2.             WebApplicationContextUtils.getRequiredWebApplicationContext(   
  3.                 (ServletContext)getDesktop().getWebApp().getNativeContext());  
ApplicationContext ctx = 
			WebApplicationContextUtils.getRequiredWebApplicationContext(
				(ServletContext)getDesktop().getWebApp().getNativeContext());

 

zk的timeout

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

Xml代码 复制代码
  1. <session-config>  
  2.         <!-- 设置session过期时间,注意单位是秒-->  
  3.         <session-timeout>1800</session-timeout>  
  4.            
  5.         <!-- Turn on the following if you want to reset the session-timeout   
  6.         counter when receiving onTimer, like any other request   
  7.         In other words, the session is never timeoout if the desktop has   
  8.         a timer.-->  
  9. <!-- 上边的注释我翻译不好,我一般是注释掉的 -->  
  10.         <!--<timer-keep-alive>true</timer-keep-alive>-->  
  11.            
  12. </session-config>  
  13.   
  14. <device-config>  
  15.         <device-type>ajax</device-type>  
  16. <!-- 设置timeout后跳转的页面 -->  
  17.         <timeout-uri>/timeout.zul</timeout-uri>  
  18.     </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、付费专栏及课程。

余额充值