trainingtrains Logo

91-9990449935

 0120-4256464

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:

  1. public static HttpServletRequest getRequest() returns the instance of HttpServletRequest.
  2. public static HttpServletResponse getResponse() returns the instance of HttpServletResponse.
  3. 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.