From bf344d616ac83db245dceb38f824d890783ad83b Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Wed, 17 Jun 2026 09:15:53 +0200 Subject: [PATCH] Defines a new struts-parameter example app to show how @StrutsParameter works --- pom.xml | 1 + struts-parameter/pom.xml | 43 ++++++++++++++ .../struts/examples/parameter/Admin.java | 27 +++++++++ .../examples/parameter/IndexAction.java | 57 +++++++++++++++++++ .../struts/examples/parameter/User.java | 39 +++++++++++++ .../src/main/resources/log4j2.xml | 15 +++++ .../src/main/resources/struts.xml | 20 +++++++ .../main/webapp/WEB-INF/examples/index.jsp | 18 ++++++ .../src/main/webapp/WEB-INF/web.xml | 21 +++++++ struts-parameter/src/main/webapp/index.jsp | 1 + 10 files changed, 242 insertions(+) create mode 100644 struts-parameter/pom.xml create mode 100644 struts-parameter/src/main/java/org/apache/struts/examples/parameter/Admin.java create mode 100644 struts-parameter/src/main/java/org/apache/struts/examples/parameter/IndexAction.java create mode 100644 struts-parameter/src/main/java/org/apache/struts/examples/parameter/User.java create mode 100644 struts-parameter/src/main/resources/log4j2.xml create mode 100644 struts-parameter/src/main/resources/struts.xml create mode 100644 struts-parameter/src/main/webapp/WEB-INF/examples/index.jsp create mode 100644 struts-parameter/src/main/webapp/WEB-INF/web.xml create mode 100644 struts-parameter/src/main/webapp/index.jsp diff --git a/pom.xml b/pom.xml index 5129b5d1..60e3c93f 100644 --- a/pom.xml +++ b/pom.xml @@ -110,6 +110,7 @@ rest-angular shiro-basic spring-struts + struts-parameter text-provider tiles themes diff --git a/struts-parameter/pom.xml b/struts-parameter/pom.xml new file mode 100644 index 00000000..8765987f --- /dev/null +++ b/struts-parameter/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + + struts-examples + org.apache.struts + 2.0.0 + + + struts-parameter + 1.0-SNAPSHOT + war + struts-parameter + A simple application demonstrating how to use @StrutsParameter annotation + + + UTF-8 + 17 + 17 + + + + + + annotations + + + org.eclipse.jetty + jetty-maven-plugin + ${jetty-plugin.version} + + + /${project.artifactId} + + CTRL+C + 8999 + 10 + + + + + diff --git a/struts-parameter/src/main/java/org/apache/struts/examples/parameter/Admin.java b/struts-parameter/src/main/java/org/apache/struts/examples/parameter/Admin.java new file mode 100644 index 00000000..09644d76 --- /dev/null +++ b/struts-parameter/src/main/java/org/apache/struts/examples/parameter/Admin.java @@ -0,0 +1,27 @@ +package org.apache.struts.examples.parameter; + +public class Admin { + private String username; + + public Admin() { + } + + public Admin(String username) { + this.username = username; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + @Override + public String toString() { + return "Admin{" + + "username='" + username + '\'' + + '}'; + } +} diff --git a/struts-parameter/src/main/java/org/apache/struts/examples/parameter/IndexAction.java b/struts-parameter/src/main/java/org/apache/struts/examples/parameter/IndexAction.java new file mode 100644 index 00000000..b92da32c --- /dev/null +++ b/struts-parameter/src/main/java/org/apache/struts/examples/parameter/IndexAction.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts.examples.parameter; + +import org.apache.struts2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; + +import java.util.ArrayList; +import java.util.List; + +public class IndexAction extends ActionSupport { + + private final List users = new ArrayList<>(); + private Admin admin; + + public String execute() throws Exception { + if (users.isEmpty()) { + users.add(new User(1, "Luk")); + users.add(new User(2, "Jan")); + } + if (admin == null) { + admin = new Admin("Michal"); + } + return SUCCESS; + } + + @StrutsParameter(depth = 2) + public List getUsers() { + return users; + } + + @StrutsParameter(depth = 2) + public Admin getAdminUser() { + return admin; + } + + @StrutsParameter(depth = 2) + public void setAdminUser(Admin admin) { + this.admin = admin; + } +} \ No newline at end of file diff --git a/struts-parameter/src/main/java/org/apache/struts/examples/parameter/User.java b/struts-parameter/src/main/java/org/apache/struts/examples/parameter/User.java new file mode 100644 index 00000000..e50d1ad4 --- /dev/null +++ b/struts-parameter/src/main/java/org/apache/struts/examples/parameter/User.java @@ -0,0 +1,39 @@ +package org.apache.struts.examples.parameter; + +public class User { + + private int id; + private String name; + + public User() { + } + + public User(int id, String name) { + this.id = id; + this.name = name; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "User{" + + "id=" + id + + ", name='" + name + '\'' + + '}'; + } +} diff --git a/struts-parameter/src/main/resources/log4j2.xml b/struts-parameter/src/main/resources/log4j2.xml new file mode 100644 index 00000000..32cbd7ec --- /dev/null +++ b/struts-parameter/src/main/resources/log4j2.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/struts-parameter/src/main/resources/struts.xml b/struts-parameter/src/main/resources/struts.xml new file mode 100644 index 00000000..d6778c42 --- /dev/null +++ b/struts-parameter/src/main/resources/struts.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + /WEB-INF/examples/index.jsp + + + + + + diff --git a/struts-parameter/src/main/webapp/WEB-INF/examples/index.jsp b/struts-parameter/src/main/webapp/WEB-INF/examples/index.jsp new file mode 100644 index 00000000..ccb87a41 --- /dev/null +++ b/struts-parameter/src/main/webapp/WEB-INF/examples/index.jsp @@ -0,0 +1,18 @@ +<%@ page contentType="text/html; charset=UTF-8" %> +<%@ taglib prefix="s" uri="/struts-tags" %> + + + Home + + + + + + + + + + + + + diff --git a/struts-parameter/src/main/webapp/WEB-INF/web.xml b/struts-parameter/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000..7f5eaf9b --- /dev/null +++ b/struts-parameter/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,21 @@ + + + + struts2 + org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter + + + + struts2 + /* + + + + index.jsp + + + diff --git a/struts-parameter/src/main/webapp/index.jsp b/struts-parameter/src/main/webapp/index.jsp new file mode 100644 index 00000000..d40e6d49 --- /dev/null +++ b/struts-parameter/src/main/webapp/index.jsp @@ -0,0 +1 @@ +<% response.sendRedirect("index"); %>