Refactor(wildcard-method-selection): Update for Struts 7 compatibility
- Added `@StrutsParameter` annotations to action parameter setter or getter.
- Implement OGNL allowlist for stricter security compliance.
- Update `web.xml` to schema version 6.0.
- Changed JSP file encoding to `UTF-8`.
diff --git a/wildcard-method-selection/src/main/java/org/apache/struts/tutorials/wildcardmethod/action/PersonAction.java b/wildcard-method-selection/src/main/java/org/apache/struts/tutorials/wildcardmethod/action/PersonAction.java
index ee0688d..5d9cc30 100644
--- a/wildcard-method-selection/src/main/java/org/apache/struts/tutorials/wildcardmethod/action/PersonAction.java
+++ b/wildcard-method-selection/src/main/java/org/apache/struts/tutorials/wildcardmethod/action/PersonAction.java
@@ -5,6 +5,7 @@
import org.apache.struts.tutorials.wildcardmethod.model.Person;
import org.apache.struts.tutorials.wildcardmethod.service.PersonService;
import org.apache.struts2.ActionSupport;
+import org.apache.struts2.interceptor.parameter.StrutsParameter;
import java.util.List;
@@ -68,7 +69,7 @@
return SUCCESS;
}
-
+ @StrutsParameter(depth = 1)
public Person getPerson() {
return person;
}
@@ -93,7 +94,7 @@
return id;
}
-
+ @StrutsParameter
public void setId(int id) {
this.id = id;
}
diff --git a/wildcard-method-selection/src/main/resources/struts.xml b/wildcard-method-selection/src/main/resources/struts.xml
index 2579f2e..cea89ac 100644
--- a/wildcard-method-selection/src/main/resources/struts.xml
+++ b/wildcard-method-selection/src/main/resources/struts.xml
@@ -7,9 +7,14 @@
<constant name="struts.devMode" value="false" />
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
+ <constant name="struts.allowlist.packageNames" value="org.apache.struts.tutorials.wildcardmethod.model" />
<package name="wildcardmethodexample" extends="struts-default">
+ <default-action-ref name="index" />
+ <action name="index">
+ <result>index.jsp</result>
+ </action>
<!-- Whatever value is before Person for the name of
the action will be the name of the method to call in
class PersonAction. For example action createPerson
diff --git a/wildcard-method-selection/src/main/webapp/WEB-INF/web.xml b/wildcard-method-selection/src/main/webapp/WEB-INF/web.xml
index 4dba10f..dceceee 100644
--- a/wildcard-method-selection/src/main/webapp/WEB-INF/web.xml
+++ b/wildcard-method-selection/src/main/webapp/WEB-INF/web.xml
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
-<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+<web-app id="WebApp_ID" version="6.0"
+ 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">
<display-name>Wildcard_Method_Struts2_Mvn</display-name>
<welcome-file-list>
diff --git a/wildcard-method-selection/src/main/webapp/input.jsp b/wildcard-method-selection/src/main/webapp/input.jsp
index 442990e..dfc4203 100644
--- a/wildcard-method-selection/src/main/webapp/input.jsp
+++ b/wildcard-method-selection/src/main/webapp/input.jsp
@@ -1,4 +1,4 @@
-<%@ page language="java" pageEncoding="ISO-8859-1" %>
+<%@ page language="java" pageEncoding="UTF-8" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
diff --git a/wildcard-method-selection/src/main/webapp/view.jsp b/wildcard-method-selection/src/main/webapp/view.jsp
index e619846..d1805af 100644
--- a/wildcard-method-selection/src/main/webapp/view.jsp
+++ b/wildcard-method-selection/src/main/webapp/view.jsp
@@ -1,4 +1,4 @@
-<%@ page language="java" pageEncoding="ISO-8859-1" %>
+<%@ page language="java" pageEncoding="UTF-8" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";