Newsletter:

(Guide) Java Reference Guide - Struts Actions

Guide : Java Reference Guide - Struts Actions

In the previous sections I demonstrated how to create a simple Struts 2 application using both XML and annotations. In these examples I emphasized that Struts 2 promotes convention over configuration and aims to reduce the amount of configuration code you have to write in order to build an application.

One thing that you might have noticed is that Struts 2 is very focused on actions — actions are the central point of a Struts 2 application and where you’ll spend most of your time when building a Struts 2 application. Actions can be defined via convention, in which the requirement for an action is simply to provide an execute() method, or they can implement the Action interface, which defines the single execute() method that returns a String. In addition to defining the execute() method, the Action interface also defines five String constants: ERROR, INPUT, LOGIN, NONE, and SUCCESS, that you are free to use as return values from your execute() method. But more importantly, these constants fit into the “bigger picture” in how actions and interceptors interact with one another.

In the last section I showed you how Struts 2 automatically populated a JavaBean property, namely “name,” into the HelloAction before its execute() method was invoked. But this begs the question about how Struts accomplished this. The answer lies in the notion of interceptors and how they interact with actions. Struts defines a host of interceptors that you can use in your application and it defines a default set of interceptors that are executed when processing each action. In the root of the struts-core-version.jar file, there is an XML file named struts-default...

[Read More..]

Courtesy:- Informit.com