Getting-Started with Struts 2 on Linux
Hi! The Tutorial shows you Step-by-Step How to Quick Start with a Struts 2 Hello-World Java Web Application on GNU/Linux Systems.
The first Benefit of Using Struts is that you don’t have to write a Controller and can concentrate on writing Business Logic in action classes.
The Tutorial make Use of the Maven Java Tool Facility to Getting-Started Easy with a Basic Struts2 Web App on Linux.
Struts 2 can Use either an XML Configuration file or Java Annotations (or both) to specify the relationship between a URL, a Java class, and a view page (such as index.jsp).
-
How to Install Struts 2 on GNU/Linux
-
Check if Maven 3+ is Setup on Linux
mvn -v
-
Generate a Maven Standard Java Web App Project:
-
Edit the pom.xml Config File
cd myWebApp
nano pom.xml
Modify the “build” Entry like:
<build> <finalName>basic_struts</finalName> </build>
Ctrl+x to Save & Exit from nano :)
-
Add Struts 2 Jar Files To Class Path.
nano ./pom.xml
Include in the “dependencies” Section:
<dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-core</artifactId> <version>[X.X.X.X]</version> </dependency>
Just Subsitute to X.X.X., the Suited Struts 2 Version (May simply Look the Latest Downloaded Struts Release!)
-
Building and Packaging to Easy Deploy on the Servlet Container.
mvn clean package
Find the Artifact Product Ready to Deploy on:
./target/basic_struts.war
-
How to Deploy a Servelet on Apache Tomcat Container
-
Then you can Browse the Struts2 StartUp Hello-World.
http://localhost:8080/basic_struts/
-
Add Logging.
This to see what’s happening under the hood…
nano ./pom.xml
Include in the “dependencies” Section:
<dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.14</version> </dependency>
Then Create a Log4J Config File
nano ./src/main/resources/log4j.xml
Append:
-
Add a Struts 2 Servlet Filter.
nano ./src/main/webapp/WEB-INF/web.xml
Insert:
struts2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter struts2 /* -
Struts 2 App Minimal XML Configuration.
nano ./src/main/resources/struts.xml
Append:
/index.jsp -
Building and Packaging Again.
mvn clean package
-
Deploy and Access the Final Struts2 Hello-World App.
http://localhost:8080/basic_struts/