Struts 2 ServletActionContext class Tutorial

The ServletActionContext class gives methods to get HttpServletRequest, HttpServletResponse, ServletContext and HttpSession objects.

It is a helpful class and prefered than ActionContext class.

Methods of ServletActionContext class

The usually utilized methods given by ServletActionContext class are as follows:

  1. public static HttpServletRequest getRequest() restores the occurrence of HttpServletRequest.
  2. public static HttpServletResponse getResponse() restores the occurrence of HttpServletResponse.
  3. public static ServletContext getServletContext() restores the occasion of ServletContext.

How to acquire occurrence of HttpSession ?

If we have the case of HttpServletRequest class, we can call the getSession() method for HttpServletRequest interface to get the occasion of HttpSession. For example:

  1. HttpServletRequest request=ServletActionContext.getRequest();  
  2. HttpSession session=request.getSession();  


  1. HttpSession session=ServletActionContext.getRequest().getSession();  

We are going to see the full case of this in next theme SessionAware interface.

javacodegeeks is optimized for learning.© javacodegeeks .
All Right Reserved and you agree to have read and accepted our term and condition