Chain Action Result Example
Posted on: January 22, 2011 at 12:00 AM
In this tutorial you will learn how to chain the action in the in struts2.2.1

Chain Action Example

Struts2.2.1 provides the feature to chain many actions into a defined sequence or work flow. This feature can be used in an application by applying Chain Result to a action. A Chain Result is an result type which intercepts an interceptor with its own result and stack. This allows to forward a request to an another action. While propagating the state.

An Example of Chain Action is given below.


<?xml version="1.0" encoding="UTF-8" ?>
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"


<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />

<package name="public" extends="struts-default">
<!-- Chain creatAccount to login, using the default parameter -->

<action name="showLogin">

<action name="doLogin" class="net.roseindia.Login">
<!-- Chain to another namespace -->

<result type="chain">
<param name="actionName">home</param>
<param name="namespace">/secure</param>


<package name="secure" extends="struts-default" namespace="/secure">

<action name="home">



package net.roseindia;
import com.opensymphony.xwork2.ActionSupport;
public class Login extends ActionSupport {

public String execute() throws Exception {
System.out.println("Login Action Called");
if(getUsername().equalsIgnoreCase("")|| getPassword().equalsIgnoreCase("")){
return ERROR;
else if(!getUsername().equals("Admin") || !getPassword().equals("Admin")){
return ERROR;
return SUCCESS;

private String username = null;

public String getUsername() {
return username;

public void setUsername(String value) {
username = value;

private String password = null;

public String getPassword() {
return password;

public void setPassword(String value) {
password = value;



<%@ taglib prefix="s" uri="/struts-tags" %>
<title>Chain Result Example</title>

<link href="<s:url value="/css/main.css"/>" rel="stylesheet"

<s:form action="doLogin" method="POST"> 
<td colspan="2">
<td colspan="2">
<s:actionerror />
<s:fielderror />
<s:textfield name="username" label="Login name"/>
<s:password name="password" label="Password"/>
<s:submit value="Login" align="center"/> 


<%@ taglib prefix="s" uri="/struts-tags" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<TITLE> Home Page </TITLE>

<BODY bgcolor="lightgreen">
<center><font face="Arier" size="16">This is Home page</font>
<font face="arier" size="14"><br>Welcome : <s:property value="username"/></font>
When you run this application it will display message as shown below:


Download this example code

Related Tags for Chain Action Result Example:



Advertisement null