Waqas Ali
Waqas Ali

Reputation: 1652

Get Request object in Struts Action Class

I read two different way to get Request object in any action class of struts which are as below

HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get( ServletActionContext.HTTP_REQUEST);

And

HttpServletRequest request =  ServletActionContext.getRequest();

I want to know what is the difference between both of them. Its look like both are same because ServletActionContext Class provides us the request object.

Upvotes: 0

Views: 2513

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 279960

ServletActionContext.getRequest() is implemented as

public static HttpServletRequest getRequest() {
    return (HttpServletRequest) ActionContext.getContext().get(HTTP_REQUEST);
}

You either do it directly or call this method. They do the same thing.

Upvotes: 1

Related Questions