• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

S2: Actions are not Servlet

 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Struts 2 action classes are most certainly not servlets, nor particularly similar.


This info forced me to dig up Struts 2 site. Here I come up with one point.

"S2 has Action classes which are extended by ActionSupport (or Action interface) classes, this is not the general requirement, you can access any Java class with execute() method, Struts will find it for you."

Am I right ?

And it means there is no HttpServletResponse/Request objects, nor any J2EE "javax.servlet.http" classes used/implemented in S2?
 
Ranch Hand
Posts: 433
Netbeans IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You *can* extend from ActionSupport but it's not a *must*. If you have an execute-method in your action it will be called automatically.
Regarding the HTTP*-Objects have a look at the Servlet Config Interceptor (http://struts.apache.org/2.0.14/docs/servlet-config-interceptor.html). You have access to those objects but you need to implement certain interfaces so Struts can inject those objects.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you right that the S2 site says that, or is it correct that S2 actions don't *have* to extend ActionSupport? I don't know if the S2 site says that, but it's true that actions don't *have* to extend ActionSupport.

That has nothing to do with the second part of your question, though. One of the main points of S2 is to abstract itself away from the servlet spec--one of the *major* pain points with Struts 1 (that's why WebWork went that route).

As the previous commenter states you *can* get access to the servlet spec objects, but there are very few situations where that's necessary. Since there are trivial, non-servlet-spec-related ways to get the attribute/parameter maps of the servlet spec objects, one more use case for accessing servlet spec objects is eliminated.

All of that combines to make action testing far, *far* easier.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks David & Joachim

David Newton wrote:I don't know if the S2 site says that, but it's true that actions don't *have* to extend ActionSupport.


Agreed, And that perticualr site/link is this and this the tip form the same link

Implementing the Action interface is optional. If Action is not implemented, the framework will use reflection to look for an execute method.


David Newton wrote:
One of the main points of S2 is to abstract itself away from the servlet spec--one of the *major* pain points with Struts 1 (that's why WebWork went that route).


hmm, that's something new to me, I didn't imagine an Java web framework without servlet spec. So it means they created all new spec for web application from scratch?

David Newton wrote:
All of that combines to make action testing far, *far* easier.


Yeah, it looks from the Action code, which has a plain "execute()"method and not depending upon any (http) parameters or states.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

So it means they created all new spec for web application from scratch?


No, it means the servlet spec is abstracted away from the application code.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If that so, can I really start developing Web application using S2 without any prior knowledge of Servlets ? After all, S2 dosen't really used those "javax.http.servlet" package..
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you can, although when something *does* go wrong you may be less likely to understand why. It's still very important to understand the underlying processes and mechanisms.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, Thanks David
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic