Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Define ServletActionContext? Why we are using ServletActionContext

 
Nagu Spartan
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You seem to have just repeated what you said then what I said, but I don't know why.
 
Nagu Spartan
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
About what?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic