Introduction of Struts 2 Result types

Introduction of Struts 2 Result types

In the Apache Struts 2 framework after executing the Action class , the target view page will be executed based on configuration in struts.xml. The result type is used to change the behaviour of view page to render the contents of action class.

The framework provides several implementations of the com.opensymphony.xwork2.Result interface, ready to use in your own applications.

Chain Result Used for Action Chaining
Dispatcher Result Used for web resource integration, including JSP integration
FreeMarker Result Used for FreeMarker integration
HttpHeader Result Used to control special HTTP behaviors
Redirect Result Used to redirect to another URL (web resource)
Redirect Action Result Used to redirect to another action mapping
Stream Result Used to stream an InputStream back to the browser (usually for file downloads)
Velocity Result Used for Velocity integration
XSL Result Used for XML/XSLT integration
PlainText Result Used to display the raw content of a particular page (i.e jsp, HTML)
Tiles Result Used to provide Tiles integration

In Struts 2 the tag plays the role of a view in the Struts2 MVC framework. The action is responsible for executing the business logic. The next step after executing the business logic is to display the view using the tag.  Often there is some navigation rules attached with the results. For example, if the action method is to authenticate a user, there are three possible outcomes.

  1.      Successful Login
  2.      Unsuccessful Login - Incorrect username or password
  3.      Account Locked.