Tutorial

Struts 2 Tutorial - Struts2 Tutorial

Published on August 4, 2022
author

Pankaj

Struts 2 Tutorial - Struts2 Tutorial

Welcome to Struts 2 Tutorial index post. Struts 2 is one of the mostly used Java Web Application Framework and recently I have wrote a lot about it. Struts 2 is built on top of Struts1 and WebWork framework that makes it highly flexible, extendable and easy to maintain.

Struts 2 Tutorial

If you want to learn Struts 2 and it’s important features then please read all the below articles in order. All these articles provide framework features in great details and comes with downloadable web application projects. Struts 2 Tutorial, struts2 tutorial

Struts 2 Tutorial for Beginners

  1. **Struts 2 Example for Beginners**This is the first article in the series, here you will learn about basics of Struts 2 with brief details about it’s architecture, framework core concepts such as Interceptors, OGNL, Action, Results, wiring the application components etc. The article also provides basic example of Struts 2 web application project with XML based configuration.
  2. Struts 2 Annotations Example ProjectJava Annotations are becoming popular in most of the Java EE frameworks and Struts 2 provides a lot of annotations that we can use to create Struts 2 web application with zero configuration i.e. without having struts configuration file. Check out the article to learn about the commonly used annotations in Struts 2 framework. The article also provides an example project built with annotations and without having any struts configuration file that you can download and play around.
  3. **Struts 2 Result Path Configuration**We can configure Struts 2 application to look for result pages at specific location, the article provide brief details about this using XML based configuration as well as annotation based.
  4. **Struts 2 No result defined for action and result input**A common error faced while working with Struts 2 application because of validation failure and there is no result configured for “input” in struts configuration file.

Struts 2 Action

  1. Struts 2 Action ClassesAction classes are at the front of our application and we invest a lot of time in designing and developing action classes. The article explains about four different ways to create action classes in Struts 2 framework. Learn about these ways and which is the good option to chose in your application action classes.
  2. Struts 2 Action Object-backed and ModelDriven ExampleMost of the times we don’t want form bean properties to be part of action classes and we want to have them in a java bean that we can use in action classes. There are two approaches to achieve this - Object-backed and ModelDriven. The article explains about both of these approaches and which is the best approach to use.
  3. Struts2 Action Messages and Action Errors ExampleWe can override ActionSupport validate() method to have form field validation at server side and return the input page with action error messages to show in result pages. Similarly we can add action messages to show in result pages.

Struts 2 Interceptors

  1. Struts 2 Interceptor Tutorial with Custom Interceptor ExampleStruts2 interceptors are the backbone of the framework and defined in struts-default package. Struts2 interceptors are great example of Chain of Responsibility pattern implementation. This article explains about the working of interceptors and how easily we can create our own interceptor and configure it for action. The article shows how we can achieve authentication across the application with the use of custom interceptors and make our code loosely coupled and achieve flexibility with code reuse.
  2. Struts2 token interceptorWe can use Struts2 token and tokenSession interceptors to handle multiple form submission problem at server side in the web application. This article explains about these interceptors in detail with a working example.
  3. Struts2 execAndWait interceptorWe can use Struts2 execAndWait interceptor to return an intermediate response page to client incase of long running action classes. Once the action class execution is finished, the final response is returned to the client. This article explains about execAndWait interceptor and how can we use this for long running action classes.

Struts 2 Tags

  1. **Struts 2 OGNL Tutorial**Struts2 uses OGNL expression language for data transfer from request to action classes bean properties and type conversion from String to objects and vice versa in result pages. The article provide details about the usage of OGNL expressions and how we can create our own type converter classes.
  2. Struts2 Data TagsStruts2 comes with rich tags that can be categorized into data, control and UI tags. This article provide details about majorly used Struts2 data tags with example project.
  3. Struts2 Control TagsStruts2 control tags are used for manipulation and navigation of data from a collection. This article provide details about the Struts2 control tags and how we can use them for conditional flow and iterate over an array or collection. We also learn about some other control tags used to sort list, merge lists, append lists and take subset of list with example project.
  4. Struts2 UI TagsStruts2 UI tags are used to generate HTML form elements in result pages. UI tags are also responsible for binding form properties to action class properties. This article provide details about mostly used UI tags with example project.

Struts 2 Localization

Struts2 Resource Bundles and Localization Struts2 provides strong support for internationalization through I18nInterceptor and resource bundles. This article explains about i18n support in Struts2 framework with different locations of resource bundles with example project.

Struts 2 Tutorial - Miscellaneous

  1. Struts2 Single and Multiple File Upload ExampleFile uploading is one of the common tasks in the web application. That’s why Struts2 provides FileUploadInterceptor interceptor that we can use to upload Single as well as multiple files on the server without using any third party tools. The article explains about this interceptor in detail with example project to upload files on server.
  2. How to get Servlet Session, Request, Response, Context Attributes in Struts 2 ActionSometimes we want to have access to Servlet API components such as Session, Request and Response in action classes. Struts2 provides a bunch of *Aware interfaces that we can implement in action classes to inject Servlet API components in action classes.
  3. Struts2 and log4j integrationThis article explains how we can integrate log4j with Struts2 framework in our web application for logging purposes.
  4. Struts2 Exception HandlingStruts2 provide convenient ways to configure error pages for exceptions thrown by our application at global package level as well as action level. Again this is done by Struts2 exception interceptor that is part of defaultStack. Check out this post for example project with usage details.
  5. Struts2 Hibernate Integration ExampleMostly we use an ORM tool in enterprise applications and Hibernate is one of the best choices available in the market. This tutorial provide details about how to integrate Hibernate with Struts2 framework in a web application with downloadable example project.

Struts 2 Interview Questions

This article lists most important Struts 2 interview questions with detailed answers to clear you through interview. There are more articles to come in Struts 2 tutorial series, do bookmark this post for future reference.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar
Pankaj

author

While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
JournalDev
DigitalOcean Employee
DigitalOcean Employee badge
May 16, 2019

your posts really helpful to me, thanks a lot Pankaj

- ashok

    JournalDev
    DigitalOcean Employee
    DigitalOcean Employee badge
    April 16, 2016

    how can I download pdf file from postgres sql database using struts 2 annotations and hibernate …? can anybody help ,pls send some example code

    - kittu

      JournalDev
      DigitalOcean Employee
      DigitalOcean Employee badge
      October 15, 2015

      Hi, Can you please help in handling csrf in struts2.

      - Deva

        JournalDev
        DigitalOcean Employee
        DigitalOcean Employee badge
        November 11, 2014

        Hi Sir, I am new to struts2 and Eclipse Environment as well as Tomcat. I did some sample application in struts1 with Netbeans6.8 IDE and Jboss4. I want to follow you to learn struts2.so I want to know that what version of Eclipse/My Eclipse ,Tomcat and etc. to build struts2 application . Thanks and Regards, Anbuselvi

        - Anbuselvi

          JournalDev
          DigitalOcean Employee
          DigitalOcean Employee badge
          October 6, 2014

          I am new in programming and i am non technical person and my age is 41. I have taken lot of interest in learning Core-Java and Advanced Java.I am studying through Video courses and through books at home But there is a confusion in Interceptors I dont know what is the use of Interceptors and How interceptors work .please help me in interceptors

          - Rajesh V Undre

            JournalDev
            DigitalOcean Employee
            DigitalOcean Employee badge
            August 23, 2014

            Hi can u help me to create an application for sending e- mail with multiple receipients and also cc, bcc. Which must include the attachments also. Login credential must be in jsp page itself.

            - Kiran G V

              JournalDev
              DigitalOcean Employee
              DigitalOcean Employee badge
              July 31, 2014

              Hi Pankaj, I follow your posts, It is really very helpful to me. Thanks for such a nice post. If possible, please post Struts2 + Spring integration also. Thanks, -Pradeep

              - Pradeep Chaubey

                JournalDev
                DigitalOcean Employee
                DigitalOcean Employee badge
                May 30, 2014

                Hi Pankaj, I am unable to open Struts UI tags :-(

                - HungryToLearn

                  Try DigitalOcean for free

                  Click below to sign up and get $200 of credit to try our products over 60 days!

                  Sign up

                  Join the Tech Talk
                  Success! Thank you! Please check your email for further details.

                  Please complete your information!

                  Become a contributor for community

                  Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

                  DigitalOcean Documentation

                  Full documentation for every DigitalOcean product.

                  Resources for startups and SMBs

                  The Wave has everything you need to know about building a business, from raising funding to marketing your product.

                  Get our newsletter

                  Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

                  New accounts only. By submitting your email you agree to our Privacy Policy

                  The developer cloud

                  Scale up as you grow — whether you're running one virtual machine or ten thousand.

                  Get started for free

                  Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

                  *This promotional offer applies to new accounts only.