Struts Tutorial «Prev  Next»


Installing Struts Jakarta Struts 7.0

Although Struts is no longer used as heavily as Spring Boot 3, can you describe the process for installing Jakarta Struts 7.
Jakarta Struts 7 is the latest iteration of the Apache Struts framework, now under the Jakarta EE umbrella. The installation process involves setting up dependencies, configuring the web application, and running a test deployment.
Installing Jakarta Struts 7
Step 1: Set Up Your Development Environment
Before installing Struts 7, ensure you have the following installed:
Step 2: Create a Maven-Based Web Application
Struts 7 can be integrated into a Maven-based web application. Create a new Maven project:
mvn archetype:generate -DgroupId=com.example -DartifactId=struts7-demo -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

Navigate into your project directory:
cd struts7-demo

Step 3: Add Jakarta Struts 7 Dependencies Modify your `pom.xml` to include Struts 7:
<dependencies>
    <!-- Jakarta Struts Core -->
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-core</artifactId>
        <version>7.0.0</version>
    </dependency>

    <!-- Jakarta Servlet API -->
    <dependency>
        <groupId>jakarta.servlet</groupId>
        <artifactId>jakarta.servlet-api</artifactId>
        <version>6.0.0</version>
        <scope>provided</scope>
    </dependency>

    <!-- Optional: JSON Plugin for REST Support -->
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-json-plugin</artifactId>
        <version>7.0.0</version>
    </dependency>

    <!-- Optional: Logging -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>2.0.9</version>
    </dependency>
</dependencies>


Then, update dependencies:
mvn clean install

Step 4: Configure `web.xml`
Create or update `src/main/webapp/WEB-INF/web.xml` to configure Struts.
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
         https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
         version="6.0">
  
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

Step 5: Create `struts.xml` Create a new file at `src/main/resources/struts.xml`:
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
    "https://struts.apache.org/dtds/struts-2.5.dtd">

<struts>
    <package name="default" namespace="/" extends="struts-default">
        <action name="hello" class="com.example.action.HelloAction">
            <result name="success">/hello.jsp</result>
        </action>
    </package>
</struts>

Step 6: Create Action Class
Create a Java class at `src/main/java/com/example/action/HelloAction.java`:

package com.example.action;

import com.opensymphony.xwork2.ActionSupport;

public class HelloAction extends ActionSupport {
    private String message;

    public String execute() {
        message = "Welcome to Jakarta Struts 7!";
        return SUCCESS;
    }

    public String getMessage() {
        return message;
    }
}

Step 7: Create JSP View
Create a JSP file at `src/main/webapp/hello.jsp`:
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head><title>Struts 7 Demo</title></head>
<body>
    <h1><s:property value="message"/></h1>
</body>
</html>

Step 8: Build and Deploy the Application
Run the following command to build the WAR file:
mvn package

Deploy `target/struts7-demo.war` to Tomcat’s `webapps` directory.
Start Tomcat and access the application:
http://localhost:8080/struts7-demo/hello

You should see the message "Welcome to Jakarta Struts 7!" on the page.

 

Conclusion Jakarta Struts 7 is configured similarly to previous versions, but it is now aligned with Jakarta EE 10. You need to use Jakarta Servlet 6.0+ and deploy on a compatible container like Tomcat 10+.
For configuring the struts for you application refer to Configuring Struts.
For Struts documentation, install notes, and downloads, see the official Struts Home page.

Remote 1