aspose file tools*
The moose likes Struts and the fly likes Define ServletActionContext? Why we are using ServletActionContext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Define ServletActionContext? Why we are using ServletActionContext" Watch "Define ServletActionContext? Why we are using ServletActionContext" New topic
Author

Define ServletActionContext? Why we are using ServletActionContext

Nagu Spartan
Ranch Hand

Joined: Jan 08, 2010
Posts: 40

Define ServletActionContext? Why we are using ServletActionContext?

why we use ServletActionContext to setAttribute. there is option to use request.setAttribute("values".values);
What is the difference of using ServletActionContext.getRequest().setAttribute("values", values); and request.setAttribute("values".values);
Can you please explain in detail.


Thanks
Nagarajan T.


Thanks & Regards,
Nagarajan T.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I assume you're talking about Struts 2 and comparing the use of ServletActionContext against implementing ServletRequestAware... although you don't say, so I'm guessing. It's helpful to TellTheDetails to avoid confusion.

Other than ServetActionContext being more difficult to test and less flexible, there's no difference. As it states in the FAQ entry, implementing ServletRequestAware is the preferred mechanism.

That said, why would you want to do this? Do you *really* need to set an attribute directly on the request? This runs counter to Struts 2 principles: unless you have a legitimate need to do so, and there aren't very many, consider using the default S2 mechanisms for delivering data to the view layer.
Nagu Spartan
Ranch Hand

Joined: Jan 08, 2010
Posts: 40
In Struts 2,
Define ServletActionContext? Why we are using ServletActionContext?

why we use ServletActionContext to setAttribute. there is option to use request.setAttribute("values".values);
What is the difference of using ServletActionContext.getRequest().setAttribute("values", values); and request.setAttribute("values".values);
Can you please explain in detail.

Thanks
Nagarajan T.


quote=David Newton]I assume you're talking about Struts 2 and comparing the use of ServletActionContext against implementing ServletRequestAware... although you don't say, so I'm guessing. It's helpful to TellTheDetails to avoid confusion.

Other than ServetActionContext being more difficult to test and less flexible, there's no difference. As it states in the FAQ entry, implementing ServletRequestAware is the preferred mechanism.

That said, why would you want to do this? Do you *really* need to set an attribute directly on the request? This runs counter to Struts 2 principles: unless you have a legitimate need to do so, and there aren't very many, consider using the default S2 mechanisms for delivering data to the view layer.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You seem to have just repeated what you said then what I said, but I don't know why.
Nagu Spartan
Ranch Hand

Joined: Jan 08, 2010
Posts: 40
I need some more explanation...

David Newton wrote:You seem to have just repeated what you said then what I said, but I don't know why.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

About what?
 
wood burning stoves
 
subject: Define ServletActionContext? Why we are using ServletActionContext