Table of contents
1.
Introduction🤔
2.
Environment Setup for Struts💻
2.1.
Setting up Java Development Kit🧑‍🔧
2.2.
Setting up Apache Tomcat🧑‍🔧
2.3.
Setting up Eclipse IDE💻
2.4.
Setting up Struts2 Libraries💻
3.
Frequently Asked Questions
3.1.
What are the Struts 2 core components?
3.2.
Why are Struts used?
3.3.
What is the distinction between Struts 1 and Struts 2?
3.4.
What configuration files are used in Struts?
3.5.
What is Struts XML?
4.
Conclusion
Last Updated: Mar 27, 2024
Medium

Environment Setup for Struts

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction🤔

Apache Struts 2 is a sophisticated, flexible framework for developing enterprise-class Java web applications. This framework is intended to simplify the whole development cycle, from application creation through deployment and maintenance over time.

struts coding ninjas

This blog will go through setting up a development environment so that you can start working with Struts 2.

Environment Setup for Struts💻

We need to follow the steps given below to set up a development environment to start working with struts 2.

  1. Setup Java Development Kit (JDK)
  2. Setup Apache Tomcat
  3. Setup Eclipse (IDE)
  4. Setup Struts2 Libraries

Are you ready to discuss the above steps in detail❓

Setting up Java Development Kit🧑‍🔧

We can get the most recent version of the SDK from Oracle's Java SE Downloads page. In the downloaded files, follow the instructions to install and configure the setup. Finally, configure the PATH and JAVA HOME environment variables to point to the directory containing java and javac, usually java_install_dir/bin and java_install_dir, respectively.

If you're using Windows and installed the SDK in C:jdk1.5.0 20, add the following lines to your C:autoexec.bat file.

set PATH = C:\jdk1.5.0_20\bin;%PATH%
set JAVA_HOME = C:\jdk1.5.0_20


Alternatively, on Windows NT/2000/XP,

  • Right-click the My Computer and select Properties, Advanced, and Environment Variables. You would then adjust the PATH value and click the OK button.
     
  • If the SDK is installed at /usr/local/jdk1.5.0 20 and you use the C shell on Unix (Solaris, Linux, etc.), add the following to your .cshrc file.

On Unix, if the SDK is installed at /usr/local/jdk_version_code and we utilise the C shell, add the following to your.cshrc file.

setenv PATH /usr/local/jdk_version_code/bin:$PATH
setenv JAVA_HOME /usr/local/jdk_version_code

 

Alternatively, if you utilise an Integrated Development Environment (IDE) such as Borland JBuilder, Eclipse, IntelliJ IDEA, or Sun ONE Studio, build and execute a primary application to validate that the IDE knows where you installed Java; otherwise, follow the IDE's setup instructions.

Setting up Apache Tomcat🧑‍🔧

We can get the most recent version of Tomcat at Apache Tomcat. After downloading the installation, unpack the binary package into an appropriate location.

By visiting http://localhost:8080/, you can access Tomcat's default web apps. If everything is in order, the following result should be displayed.

setting up apache tomcat struts

Use the following instructions on a Unix (Solaris, Linux, etc.) system to start Tomcat.

$CATALINA_HOME/bin/startup.sh


or

/usr/local/apache-tomcat-6.0.33/bin/startup.sh

Setting up Eclipse IDE💻

Eclipse must be installed. Get the most recent Eclipse binaries from eclipse’s download page. After downloading the installation, unpack the binary package into an appropriate location.

The following result should be displayed if all goes well after a successful startup.

setting up eclipse ide struts

Use the following instructions to launch Eclipse on a Unix (Solaris, Linux, etc.) workstation.

$/usr/local/eclipse/eclipse

Setting up Struts2 Libraries💻

If everything goes fine, you can now proceed to configure your Struts2 framework. The basic procedures for downloading and installing Struts2 on your PC are as follows.

  • Choose whether to install Struts2 on Windows or Unix, and then go to the next step to download the .zip file for Windows and the .tz file for Unix.
     
  • Struts2 binaries may be downloaded at https://struts.apache.org/download.cgi 
     
  • When you unzip the downloaded file, you will see the following directory structure under C:struts-version_code.
setting up struts2 libraries

The second step is to extract the zip file to a convenient location.

Note -  If you do not correctly configure your CLASSPATH variable, you will have problems while launching your programme.

Frequently Asked Questions

What are the Struts 2 core components?

The three major Struts2 building components are the Action, Interceptor, and Result pages. Struts2 allows you to define and customise action classes in various ways.

Why are Struts used?

Struts is an open-source framework that utilises a Model, View, Controller (MVC) architecture that extends the Java Servlet API. It allows you to build stable, extendable, and adaptable online applications using standard technologies like JSP pages, JavaBeans, resource bundles, and XML.

What is the distinction between Struts 1 and Struts 2?

Struts 1 supports separate Request Processors (lifecycles) for each module, but all modules must utilise the same lifecycle. Struts 2 allows the construction of several lifecycles for each Action using interceptor stacks. Custom stacks can be built and applied to numerous Actions as needed.

What configuration files are used in Struts?

XML File. The struts.xml file provides configuration information that you will edit when actions are created. This file may be used to alter an application's default settings, such as struts.

What is Struts XML?

The struts.xml file contains the configuration data that will be changed when actions are generated. DevMode = false, as well as other default parameters provided in property files, can be altered for an application that uses this file, such as struts.

Conclusion

In this article, we have extensively discussed setting up the environment for Struts 2. 

Do you not feel eager to read/explore additional information on the subject of Struts 2 after reading about how to set up the environment for Struts 2? See the Struts 2 documentationStruts Tutorial for beginnersStruts 2 Intro, and 15 Best Java frameworks to use in 2022-Coding Ninjas.

Recommended Readings:

Refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. Enrol in our courses and refer to the mock test and problems available. Take a look at the interview experiences and interview bundle for placement preparations.

Do upvote our blog to help other ninjas grow. 

Coding Ninjas

Happy Learning Ninja! 🥷

Live masterclass