Accessing Java EE Scope Objects

This section describes how to access Java EE scope objects (like HttpServletRequest and HttpSession) from ZK applications. These objects are essential for interacting with the underlying Java EE environment and accessing request/response data, session attributes, and other web container features.

These utilities provide a bridge between ZK’s component-based architecture and the standard Java EE web environment.

Executions

org.zkoss.zk.ui.Executions

getCurrent

Executions.getCurrent()

Retrieves the current execution which contains HTTP request/response.

get HttpServletRequest

Executions.getCurrent()

Retrieves the current execution which contains HTTP request/response.

get HttpServletRequest

HttpServletRequest req = (HttpServletRequest)Executions.getCurrent().getNativeRequest();

getNativeRequest()

Sessions

org.zkoss.zk.ui.Sessions

Get Current Session

Sessions.getCurrent()

Retrieves the current ZK-wrapped session.

Get HttpSession

HttpSession nativeSession = (HttpSession) Sessions.getCurrent().getNativeSession();