Struts 2 Getting Started With Hello-World Example on Gnu/Linux

May 9, 2017 | By the+gnu+linux+evangelist.

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).

Struts 2 Quick Start on Linux - Featured
  1. How to Install Struts 2 on GNU/Linux

    Struts 2 Linux Installation
  2. Check if Maven 3+ is Setup on Linux

    mvn -v

    How to Install Latest Apache Maven on Linux

  3. Generate a Maven Standard Java Web App Project:

    Maven Create Web App Project
  4. 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 :)

  5. 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!)

  6. 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
  7. How to Deploy a Servelet on Apache Tomcat Container

    Tomcat Easy Deploying Guide
  8. Then you can Browse the Struts2 StartUp Hello-World.

    http://localhost:8080/basic_struts/
  9. 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:

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
     
    
  10. Add a Struts 2 Servlet Filter.

    nano ./src/main/webapp/WEB-INF/web.xml

    Insert:

    
    struts2
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    
    
    struts2
    /*
    
    
  11. Struts 2 App Minimal XML Configuration.

    nano ./src/main/resources/struts.xml

    Append:

    
    
    
    
    
    
    /index.jsp
    
    
    
    
  12. Building and Packaging Again.

    mvn clean package
  13. Deploy and Access the Final Struts2 Hello-World App.

    http://localhost:8080/basic_struts/

QuickChic Theme • Powered by WordPress