Struts Overview

Click to rate this post!
[Total: 0 Average: 0]

Struts Overview

What is Struts

The struts system is utilized to create MVC-based web application. The struts system was at first made by Craig McClanahan and gave to Apache Foundation in May, 2000 and Struts 1.0 was discharged in June 2001. The present stable arrival of Struts will be Struts in March 2, 2014. This struts 2 instructional exercise covers every one of the themes of Struts  Framework with disentangled cases for learners and experienced people.

Struts 2 Framework

The Struts 2 system is utilized to create MVC (Model View Controller) based web applications. Struts  is the mix of webwork system of open symphony and struts 1.

                                               struts2 = webwork + struts1

The Struts 2 gives backings to POJO based activities, Validation Support, AJAX Support, Integration support to different systems, for example, Hibernate, Spring, Tiles and so forth, support to different outcome sorts, for example, Free marker, Velocity, JSP.

JAVA Tutorial Video

Struts Features

  1. Configurable MVC components
  2. POJO based actions
  3. AJAX support
  4. Integration support
  5. Various Result Types
  6. Various Tag support
  7. Theme and Template support
 Model 2 (MVC) Architecture

Struts 2 depends on the MVC (Model View Controller) plan design. The MVC configuration design comprises of three modules model, view and controller. Demonstrate the model speaks to the state (information) and business rationale of the application. View The view module is dependable to show information i.e. it speaks to the introduction. Controller The controller module goes about as an interface among view and model. It catches every one of the solicitations i.e. gets information and charges to Model/View to change as needs be.MVC Architecture of Structs1Advantage

  • Easy to maintain
  • Easy to extend
  • Easy to test
  • Better separation of concerns

Interceptor is a question that is summoned at the preprocessing and postprocessing of a demand. In Struts 2, interceptor is utilized to perform operations, for example, approval, special case dealing with, internationalization, showing middle of the road result and so forth.

Favorable position of interceptors

Pluggable If we have to evacuate any worry, for example, approval, exemption taking care of, logging and so forth from the application, we don’t have to redeploy the application. We just need to expel the section from the struts.xml record.

 Struts 2 default interceptors

Alias,autowiring,chain ,checkbox ,cookie ,conversionError ,createSession ,clearSession ,debugging ,externalRef,execandWait ,exception ,fileUpload ,i18n ,jsonValidation ,logger ,store,modeldriven ,scopedModelDriven ,params ,actionMappingParas,prepare ,profiling ,roles ,scope ,servletConfig ,sessionAutowiring,staticParams,timer ,token,tokenSession ,validation ,workflow,annotationWorkflow, multiselect.

Struts 2 ValueStack 

A value Stack is essentially a stack that contains application particular questions, for example, activity objects and other model protest. At the execution time, activity is put on the highest point of the stack. We can place protests in the valuestack, question it and erase it.

ValueStack Interface

The struts 2 system gives an interface to manage valuestack. It gives numerous helpful strategies.

Methods of ValueStack interface

public String findString(String expr)

 public Object findValue(String expr)

 public Object findValue(String expr, Class c)

 public Object peek()

public Object pop()

public void push(Object o)

 public void set(String key, Object value)

 public int size()

Struts 2 ActionContext

The ActionContext is a holder of items in which activity is executed. The qualities put away in the ActionContext are one of a kind for each string (i.e. ThreadLocal). So we don’t have to make our activity string safe. The ActionInvocation speaks to the execution condition of an activity. It holds the activity and interceptors objects.

 Struts 2 ActionInvocation

ActionInvocation Interface

The struts structure gives ActionInvocation interface to manage ActionInvocation. It gives numerous techniques, some of them can be utilized to get the case of ValueStack, ActionProxy, ActionContext, Result.

No.                        Method
1) publicActionContext getInvocationContext()
2) public ActionProxy getProxy()
3) public ValueStack getStack()
4) public Action getAction()
5) public void invoke()
6) public Result getResult()

Struts 2 standard flow

Standard flow Architecture

Struts 2 Configuration File

The struts application contains two fundamental arrangement documents struts.xml record and document. The record is utilized to supersede the default estimations of default.xml document gave by struts structure. So it is not obligatory. For the most part, you won’t utilize document. We will find out about it later.

1) package element

We can without much of a stretch gap our struts application into sub modules. The bundle component determines a module. You can have at least one packages in the struts.xml document.

Characteristics of package component

  • name is must for characterizing any package.

namespace It is a discretionary quality of package. On the off chance that namespace is absent,/is expected as the default namespace. In such case, to conjure the activity class, you require this

URI: /actionName.action

On the off chance that you indicate any namespace, you require this.

URI: /namespacename/actionName.action

  • exends The package component for the most part expands the struts-default bundle where interceptors and result sorts are characterized. In the event that you broaden struts-default, every one of the activities of this bundle can utilize the interceptors and result-sorts characterized in the struts-default.xml record.

2) activity component

The activity is the subelement of bundle and speaks to an activity.

Properties of activity component

  • name is must for characterizing any activity.

class is the discretionary property of activity. On the off chance that you discard the class quality, ActionSupport will be considered as the default activity. A basic activity might be as:

<action name=”product”>

Technique It is a discretionary trait. On the off chance that you don’t indicate technique characteristic, execute strategy will be considered as the strategy for activity class. So this code:

<action name=”product” class=”com.javaspot.Product“>

<action name=”product” class=”com.javaspot.Product” method=”execute”>

On the off chance that you need to conjure a specific technique for the activity, you have to utilize strategy property.

3) result component

It is the sub component of activity that indicates where to forward the demand for this activity.

  • Traits of result component

name is the discretionary trait. On the off chance that you overlook the name characteristic, achievement is accepted as the default result name.

sort is the discretionary characteristic. In the event that you discard the sort quality, dispatcher is expected as the default result sort.

Multiple Configuration File 

For a huge application, it is smarter to utilize various setup document that one with the goal that it might be anything but difficult to deal with the application.

We can make numerous arrangement documents however we have to characterize it in the struts.xml record. The includesub-component of struts is utilized to characterize the bolstered arrangement document.

Case to make various arrangement documents

We should see the straightforward case to characterize numerous setup records.

1) Define entry of multiple configuration files in struts.xml

In this struts.xml record, we have characterized 2 setup documents struts-first.xml document and struts-second.xml record.

The struts-first.xml record is situated inside the main catalog and struts-second.xml document is situated inside the second registry.


<?xml version=”1.0″ encoding=”UTF-8″ ?>

<!DOCTYPE struts PUBLIC “-/Apache Software Foundation//DTD Struts

Setup 2.1//EN” “”>


<package name=”default1″ namespace=”/” extends=”struts-default”>


<include file=”first/struts-first.xml”></include>

<include file=”second/struts-second.xml”></include>


2) Create configuration files

we make two setup documents that characterizes activity with comes about.


<?xml version=”1.0″ encoding=”UTF-8″ ?>

<!DOCTYPE struts PUBLIC “-/Apache Software Foundation//DTD Struts

Design 2.1//EN” “”>


<package name=”first” namespace=”/first” extends=”struts-default”>

<action name=”hello” class=”com.javaspot.Welcome”>






<?xml version=”1.0″ encoding=”UTF-8″ ?>

<!DOCTYPE struts PUBLIC “-/Apache Software Foundation//DTD Struts

Design 2.1//EN” “”>


<package name=”second” namespace=”/second” extends=”struts-default”>

<action name=”hello” class=”com.javaspot.Welcome”>





Other Required Resources

To run this application, we require following assets:

  • jsp
  • java
  • View Components


This jsp page makes two connections.


<a href=”first/hello”>first namespace</a>|

<a href=”second/hello”>second namespace</a>

 Activity class

It is the basic Action class containing just execute technique.

bundle com.javaspot;

open class Welcome {

open String execute(){

return “achievement”;



2 view components

The name of 2 see segments are same i.e. welcome.jsp however both are found in an unexpected way.


It is situated inside the principal registry under root.

<h1>Welcome to first namespace</h1>



<p>It is situated inside the second index under root.</p>

<div class=”codeblock”><pre name=”code” class=”java” >

<h1>Welcome to second namespace</h1>

 Struts 2 Multiple Namespace 

We can characterize numerous namespaces in struts.xml document by the namespace quality of bundle component. As we probably am aware, default namespace is (root).

to our newsletter

Drop Us A Query

Trending Courses
  • Selenium with python
    Selenium with Python Training
  • As we know, that Selenium with Python Web Browser Selenium Automation is Gaining Popularity Day by Day. So many Frameworks and Tools Have arisen to get Services to Developers.

  • machine learning with python
    Machine Learning with Python Training
  • Over last few years, Big Data and analysis have come up, with Exponential and modified Direction of Business. That operate Python, emerged with a fast and strong Contender for going with Predictive Analysis.

  • Data science with R
    Data Science With R Training
  • Understanding and using Linear, non-linear regression Models and Classifying techniques for stats analysis. Hypothesis testing sample methods, to get business decisions.

  • data science with python
    Data Science with Python Training
  • Everyone starts Somewhere, first you learn basics of Every Scripting concept. Here you need complete Introduction to Data Science python libraries Concepts.

  • devops with azure
    Devops with Azure Training
  • As we Know Azure DevOps is a Bunch of Services, in guiding Developers. It contains CI/CD, pipelines, code Repositories, Visual Reporting Tools and more code management with version control.

  • python training
    Python Certification Training
  • Python is a dynamic interrupted language which is used in wide varieties of applications. It is very interactive object oriented and high-level programming language.

100% Secure Payments. All major credit & debit cards accepted.

Call Now Button