Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

Struts Roseindia

Here we will discuss in detail about the Struts framework, its latest release, features, architecture and versions.


Struts 2 Tutorial and Examples Struts General Availability - released Login form in Struts2 version 2.3.16 Struts 2 Login Application Struts 2 version released Struts 2 version released Struts 2 Hello World Annotation Example Struts Roseindia Struts 2 Tutorial: Easy steps to learn Struts 2 Difference between Struts and Spring Apache Struts launched to fix vulnerable Feature Struts2 Application in Eclipse: Running the application in Eclipse IDE Struts 2 Hello World Application using Eclipse Interceptors in Struts 2 Struts 2 Action Tag Struts 2 in Agile Development Environment Struts 2 UI Tags Generic Tags Creating own Interceptor What are Interceptors in Struts 2 and how do they work? Results Value Stack / OGNL Action in Struts 2 Framework Struts 2 Interceptors Struts Maven - How to use Maven dependency of Struts Download Struts How Struts 2 Framework works? Architecture of Struts 2 Framework Features and Enhancements in Struts Struts 2 Tutorials - Struts version Struts 1 Tutorial and example programs Struts Tutorial What is Struts Struts Flow Diagram Step By Step Struts Tutorial Struts 2 Login Form Example Struts Video Tutorials Struts 2 Hello World Example Introduction to Struts 2 Framework Downloading and Installing Struts 2.3.8 In Struts What is Model? What is Struts? Download Struts What is Struts Framework? Struts Framework Latest Version of Struts Framework Downloading Struts Official example Struts 2.3.8 released with new features Struts 2.3.8 Tutorials and Examples Hibernate4 Struts Integration

Struts 2 Framework is used to develop enterprise web application. It is an open source framework. For this we require Servlet API 2.4, JSP API 2.0 and Java 5. Struts 2 Framework encourages Model-View-Controller based architecture. It is made such to make the work easier by dividing the work in three different parts. Struts 2 framework builds, develops and maintains the whole application. It is based on an Interface and all the base classes are given an extra application.

Struts 2 Tags contain output data and provide style sheet driven markup that helps in creating dynamic web applications with less coding. Tags also support validation and localization of coding offering more utilization.

Struts 2 Interceptors is a powerful mechanism that enhances the control on a request. Interceptors perform multiple tasks including Logging, Validation, File Upload, Double-submit guard, exception handling, internationalization, displaying intermediate result etc. Controller call Interceptors before and after the execution of Action.

Features of Struts 2

  • Simple and easy web app development
  • POJO based actions
  • classes are based on interfaces
  • core interfaces are independent from HTTP
  • Any class can be used as an action class
  • JavaBean is used to input properties in action class
  • Struts 2 actions can be easily integrated in Spring
  • Ajax support helps to make apps more dynamic

Struts 2 Architecture:

Model: contains the data and the business logic and rules that govern the access of data and update the data.

View: is the interface that interacts with outside world and displays the result. There can be multiple view for different purposes.

Controller: controls the interaction between the user, model and view. It maps the request sent by user to a specific action and then invokes it.

Lifecycle of a Request in Struts 2 Framework:

  • A user sends request to the server
  • Controller maps the request and determines which Action to invoke.
  • Interceptors are applied to the request.
  • Action is executed to perform database operation'
  • Output is rendered.
  • Interceptors are applied again in reverse order.
  • Finally the control is returned to the servlet container, which sends the output to the user

The list of Struts Framework:

  • Struts - s the latest stable release
  • Struts 2.3.8
  • Struts 2.2.1
  • Struts 2.1.8
  • Struts 2
  • Struts 1

Struts 2 Login Form Example:

package net.roseindia;

import com.opensymphony.xwork2.ActionSupport;

import java.util.Date;

* <p> Validate a user login. </p>


public class Login extends ActionSupport {

public String execute() throws Exception {

System.out.println("Validating login");

if(!getUsername().equals("Admin") || !getPassword().equals("Admin")){

addActionError("Invalid user name or password! Please try again!");

return ERROR;

return SUCCESS;


// ---- Username property ----

* <p>Field to store User username.</p>
* <p/>


private String username = null;

* <p>Provide User username.</p>

* @return Returns the User username.


public String getUsername() {

return username;


* <p>Store new User username</p>

* @param value The username to set.


public void setUsername(String value) {

username = value;


// ---- Username property ----

* <p>Field to store User password.</p>
* <p/>


private String password = null;

* <p>Provide User password.</p>

* @return Returns the User password.


public String getPassword() {

return password;


* <p>Store new User password</p>

* @param value The password to set.


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


Here is the code of struts.xml file:

<?xml version="1.0" encoding="UTF-8" ?>


"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"



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

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

<result name="error">/error.jsp</result>

<exception-mapping exception="java.lang.Exception"

result="error" />

<action name="showLogin">

<action name="doLogin" class="net.roseindia.Login">
<result name="input">/pages/login.jsp</result>
<result name="error">/pages/login.jsp</result>


<!-- Add packages here -->
Here is the code of login.jsp file:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<%@ taglib prefix="s" uri="/struts-tags" %>
<title>Struts 2 Login Application!</title>
<link href="<s:url value="/css/main.css"/>" rel="stylesheet" type="text/css"/>

<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"/>



Share on Google+Share on Google+

Struts Roseindia

Posted on: October 5, 2013 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Struts Roseindia  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image