130
ServletActionContext class
The ServletActionContext class provides methods to get HttpServletRequest, HttpServletResponse, ServletContext and HttpSession objects.
It is a convenient class and prefered than ActionContext class.
Methods of ServletActionContext class
The commonly used methods provided by ServletActionContext class are as follows:
- public static HttpServletRequest getRequest() returns the instance of HttpServletRequest.
- public static HttpServletResponse getResponse() returns the instance of HttpServletResponse.
- public static ServletContext getServletContext() returns the instance of ServletContext.
How to obtain instance of HttpSession ?
If we have the instance of HttpServletRequest class, we can call the getSession() method of HttpServletRequest interface to get the instance of HttpSession. For example:
OR
We are going to see the full example of this in next topic SessionAware interface.
Next TopicStruts2 SessionAware Interface Example