Struts 2 Tutorial
RoseIndia Struts 2 Tutorial and Online free training helps you learn new elegant Struts 2 Framework with examples. Struts 2 is very elegant and flexible front controller framework based on many standard technologies like Java Filters, Java Beans, ResourceBundles, XML etc.
Struts 2 Training! Get Trained Now!!!
- Struts 2 Features
It is very extensible as each class of the framework is based on an Interface and all the base classes are given an extra application and even you can add your own.
- Struts 2 History
Apache Struts is an open-source framework that is used for developing Java web application. Originally developed by the programmer and author Craig R. McClanahan this was later taken over by the Apache Software Foundation in 2002.
- Struts 2 Architecture
Struts and webwork has joined together to develop the Struts 2 Framework. Struts 2 Framework is very extensible and elegant for the development of enterprise web application of any size. In this section we are going to explain you the architecture of Struts 2 Framework.
-
Why Struts 2
The new version Struts 2.0 is a combination of the Sturts action framework and Webwork.
- Struts 1.x Vs
Struts 2.x
In the following section, we are going to compare the various features between the two frameworks. Struts 2.x is very simple in comparison to the struts 1.x, few of its excelling features are:
- Downloading and Installing Struts 2
In this section we will download and install the Struts 2.0 on the latest version of Tomcat container. We will first download tomcat and configure it as our development server.
Struts 2 Hello World Application - Creating the
development directory Structure
In this section we will create directory structure of our Struts 2 Hello World application based on Struts 2 framework. Our Struts 2 Hello World application is your first step towards developing applications based on Struts 2 framework.
- Writing
Jsp, Java and Configuration files
In this section we will write JSP, Java and required configuration files for our Struts 2 Hello World application. Now in struts 2 struts.xml is used to configure the applications. We will also deploy and test the application.
- Struts 2 xml configuration file
In this section we will introduce you with the struts.xml file. This section explains you how best you can use the struts.xml file for you big projects.
Struts 2 Actions - Struts 2
Actions Example
When a client request matches the action's name, the framework uses the mapping from struts.xml file to process the request.
- Struts 2
Actions Introduction
When a client request matches the action's name, the framework uses the mapping from struts.xml file to process the request. The mapping to an action is usually generated by a Struts Tag.
- Struts
2 Redirect Action
In this section, you will get familiar with struts 2 Redirect action and learn to use it in the struts 2 application.
Struts 2 Login Application - Developing Login Application in Struts 2
In this section we are going to develop login application based on Struts 2 Framework. Our current login application does not validate the user against the database.
- Adding
Validation to Struts 2 Login Application
In this section we will write the code to validate the login application. After completing this section you will be able to write validations for your Struts 2 projects.
- Running and
testing application
In this section we will run the example on Tomcat 6.0 server and check how it works.
- Client Side
Validation in Struts 2 Login Application
In this section we will see how to write code that will generate Java Script code for client side validation. In the last section we developed Login-validator.xml configuration file for defining the server side validation.
-
Validations using Struts 2 Annotations
In this section we are going to validate our login application using Annotations in Action class. Our current login application does not validate the user against the database.
More Struts Validator Examples
User input validations are an integral part of any web application. With the release of Struts 2, validation are now much easy and robust. Struts 2 support Ajax based and even server side validations.
-
Login/Logout With Session
In this section, we are going to develop a login/logout application with session. This application checks the user authentication. Whenever you run, it takes a user id and a password (Both the user id and password is "admin") it displays the welcome page, when both fields are correctly filled.
-
Connecting to MySQL Database in Struts 2 (Struts 2 MySQL)
In this section, You will learn to connect the MySQL database with the struts 2 application. -
Rich Editor Example
In this section, you will learn how to create pagination in struts 2. -
Validate TextArea
In this section, you will learn how to validate your text area in struts 2. A text area contains 1 to 250 characters. It cann't support "null" value.
Struts 2 Tags - Struts Tags
In this section we will introduce you with the tags provided along with Struts 2 framework. It is necessary to understand all the tags provided along with Struts 2 framework.
Struts 2 Tags Examples
-
Struts 2 Tags Examples (Generic Tags)
Struts 2 tags tutorials and examples. -
Control Tags-If / Else If / Else
In this section we are going to discuss the various control tags ( The Control Tags are used for flow control such as if, else and iterate.). -
Append Tag (Control Tags) Example
In this section, we are going to describe the append tag. The append tag is a generic tag that is used to merge multiple iterators into one iterator. -
Generator Tag (Control Tags) Example
In this section, we are going to describe the generator tag. The generator tag is a generic tag that is used to generate iterators based on different attributes passed. -
Generator Tag (Control Tags) Using Count Attributes
In this section, we are going to describe the generator tag using thecount
attributes. -
Generator Tag (Control Tags) Using an Iterator with Id Attributes
In this section, we are going to describe the generator tag using the id attributes. -
Iterator Tag (Control Tags) Example
In this section, we are going to describe the Iterator tag. Iterator tag is used to iterate over a value. An iterable value can be either of: java.util.Collection or java.util.Iterator. -
Merge Tag (Control Tags) Example
In this section, we are going to describe the merge tag. The merge tag is a generic tag that is used to merge iterators. The successive call to the merge iterator causes each merge iterator to have a chance to expose its elements, subsequently next call allows the next iterator to expose its element. -
Subset Tag (Control Tags) Example
In this section, we are going to describe the subset tag. The subset tag is a generic tag that takes an iterator and outputs a subset of it. It delegates to org.apache.struts2.util.SubsetIteratorFilter internally to perform the subset functionality. -
Subset Tag (Control Tags) Example Using Count
In this section, we are going to describe the subset tag using the count parameter. The count parameter indicates the number of entries to be set in the resulting subset iterator. -
Subset Tag (Control Tags) Example Using Start
In this section, we are going to describe the subset tag using the start parameter. The start parameter is of integer type. It indicates the starting index (eg. first entry is 0) of entries in the source (needed to make available as the first entry in the resulting subset iterator). -
Action Tag (Data Tag) Example
In this section, we are going to describe the action tag. The action tag is a generic tag that is used to call actions directly from a JSP page by specifying the action name and an optional namespace. -
Bean Tag (Data Tag) Example
In this section, we are going to describe the Bean Tag. The Bean tag is a generic tag that is used to instantiates a class that confirms to the JavaBeans specification. -
Date Tag (Data Tag) Example
In this section, we are going to describe the Date tag. The date tag allows to format a Date in a quick and easy way. User can specify a custom format (eg. "dd/MM/yyyy hh:mm"), can generate easy readable notations (like "in 2 hours, 14 minutes"), or can just fall back on a predefined format with key 'struts.date.format' in the properties file. -
Include Tag (Data Tag) Example
In this section, we are going to describe the include tag. The include tag is a generic tag that is used to include a servlet's output (result of servlet or a JSP page) to the current page. -
Param Tag (Data Tag) Example
In this section, we are going to describe the param tag. The param tag is a generic tag that is used to parameterize other tags. For example the include tag and bean tag. The parameters can be added with or without a name as a key. -
Set Tag (Data Tag) Example
In this section, we are going to describe the Set tag. The set tag is a generic tag that is used to assign a value to a variable in a specified scope. -
Text Tag (Data Tag) Example
In this section, we are going to describe the text tag. The text tag is a generic tag that is used to render a I18n text message. -
Property Tag (Data Tag) Example
In this section, we are going to describe the property tag. The property tag is a generic tag that is used to get the property of a value, which will default to the top of the stack if none is specified. -
Struts 2 Tags (UI Tags) Examples
Form Tags Examples -
Auto Completer Example
In this section, we are going to describe the autocompleter tag. The autocompleter tag always displays a dropdown list with the options that have at least a partial match with entered text in the textbox. If the user clicks on the dropdown button then all options shown in the dropdown list. -
Checkbox Tag (Form Tag) Example
In this section, we are going to describe the checkbox tag. The checkbox tag is a UI tag that is used to render an HTML input element of type checkbox, populated by the specified property from the ValueStack. -
Checkboxlist Tag (Form Tag) Example
In this section, we are going to describe the checkboxlist tag. The checkboxlist tag is a UI tag that creates a series of checkboxes from a list. Setup is like <s:select /> or <s:radio />, but creates checkbox tags. -
Combobox Tag (Form Tag) Example
In this section, we are going to describe the combobox tag. The combo box is basically an HTML INPUT of type text and HTML SELECT grouped together to give you a combo box functionality. -
Datetimepicker Tag (Form Tag) Example
In this section, we are going to describe the datetimepicker tag. The datetimepicker tag is a UI tag that is used to render a date/time picker in a dropdown container. 0 -
Doubleselect Tag (Form Tag) Example
In this section, we are going to describe the doubleselect tag. The doubleselect tag is a UI tag that renders two HTML select elements with second one changing displayed values depending on selected entry of first one. -
File Tag (Form Tag) Example
In this section, we are going to describe the file tag. The file tag is a UI tag that renders an HTML file input element achieved through browsing. -
Form Tag Example
In this section, we are going to describe the form tag. The form tag is a UI tag that renders HTML an input form. 1 -
Label Tag (Form Tag) Example
In this section, we are going to describe the label tag. The label tag is a UI tag that is used to render an HTML LABEL that allows to output label:name type of combinations that has the same format treatment as the rest of UI controls. -
Optiontransferselect Tag (Form Tag) Example
In this section, we are going to describe the Optiontransferselect tag. The Optiontransferselect tag is a UI tag that creates an option transfer select component. -
Optgroup Tag (Form Tag) Example
In this section, we are going to describe the optgroup tag. The optgroup tag is a UI tag that creates an optgroup component which needs to reside within a select tag<s:select>
. 2 -
Password Tag (Form Tag) Example
In this section, we are going to describe the password tag. The password tag is a UI tag that renders an HTML input tag of type password. -
Radio Tag (Form Tag) Example
In this section, we are going to describe the radio tag. The radio tag is a UI tag that renders a radio button input field. -
Reset Tag (Form Tag) Example
In this section, we are going to describe the reset tag. The reset tag is a UI tag that is used with the form tag to provide form resetting. 3 -
Select Tag (Form Tag) Example
In this section, we are going to describe the select tag. The select tag is a UI tag that is used to render an HTML input tag of type select. -
Submit Tag (Form Tag) Example
In this section, we are going to describe the submit tag. The submit tag is a UI tag that is used to render a submit button. The submit tag is used with the form tag to provide asynchronous form submissions. -
Textarea Tag (Form Tag) Example
In this section, we are going to describe the textarea tag. The textarea tag is a UI tag that is used to render an HTML textarea. 4 -
Textfield Tag (Form Tag) Example
In this section, we are going to describe the textfield tag. The textfield tag is a UI tag that is used to render an HTML input field of type text. -
Updownselect Tag (Form Tag) Example
In this section, we are going to describe the updownselect tag. The updownselect tag is a UI tag that creates a select component with buttons to move up and down the elements in the select component.
Non-Form UI Tags -
Actionerror and Actionmessage Tags (Non-Form UI Tags) Example
In this section, we are going to describe the actionerror and actionmessage tags. The actionerror tag is a UI tag that renders action errors (in the jsp pages.) if they exists while the actionmessage tag renders action messages if they exists. 5 -
Fielderror Tag (Non-Form UI Tags) Example
In this section, we are going to describe the fielderror tags. The fielderror tag is a UI tag that renders field errors if they exists. -
TabbedPanel (Ajax Tag) Example
In this section, you will learn about the tabbedPanel tag. This is an Ajax component, where each tab is either a local content or a remote content (refreshed each time when user selects that tab). - tree
and treenode (Ajax Tag) tags Example
In this section, you will learn about the tree and treenode tags. These both work with the Ajax support.
- Div (Ajax Tag) tag
Example
In this section, you will learn about the div tag. The div tag is an Ajax component that is used with Ajax that refreshes the contents of a particular section without refreshing the entire page.
Struts 2 Examples - Struts 2 Date
In this section we will discuss the date processing functionalities available in the Struts 2 Framework.
- Date
Format Examples
In this tutorials you will learn about Date Format function in Struts 2. We have provided fully tested example code to illustrate the concepts.
- Struts
2 datepicker Example
In this section we will show you how to develop datetimepicker in struts 2. Struts 2 uses the dojo toolkit for creating date picker.
- Struts 2 Format Examples
In this section you will learn how to format Date and numbers in Struts 2 Framework. Our Struts 2 Format Examples are very easy to grasp and you will learn these concepts in very small time.
- Struts 2 File Upload
In this section you will learn how to write program in Struts 2 to upload the file on the server. In this example we are also providing the code to save the uploaded file in any directory on the server machine.
Struts 2 Resources Examples - Struts 2
Resources Examples
The struts 2 resources examples
- Static Parameter
In this section, we will develop a simple application to access the static parameters. We will use a JavaBean to set and get the static parameters. Each static parameter has a value.
-
Accessing Session Object
In this section, we will develop a simple application to access the framework resources like the session object, session context and the last accessed session time. 6 -
Access Request and Response
In this section, you will learn to develop an application that accesses the request and response object in struts 2 application.
Struts 2 Tools - Struts 2
Eclipse Plugin
This page contains the examples and the list of plugins that are available for Struts 2 Development using Eclipse IDE.
- Struts 2 IDE
This page contains the list of IDEs available to ease the development of Struts 2 Framework based applications. The IDE for Struts 2 will actually make the development cycle much easier.
- Struts 2 Application
Developing user registration application based on Struts 2 Framework. This Struts 2 Application is a simple user registration application that will help you to learn how to develop real world applications using Struts 2 Framework.
- Struts 2 Ajax
In this section we explain you Ajax based development in Struts 2. Struts 2 provides built-in support for Ajax using Dojo toolkit.
Download Source Code
of Struts 2 Tutorial