Skip to content

Commit 53099a4

Browse files
committed
Refactor(preparable-interface): Update for Struts 7 compatibility
- Added `@StrutsParameter` annotations to action parameter setter or getter. - Added `OGNL allowlist` to comply with stricter security policies. - Updated `web.xml` to schema version 6.0.
1 parent 3fab6ab commit 53099a4

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

preparable-interface/src/main/java/org/apache/struts/edit/action/EditAction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.apache.struts.edit.service.EditServiceInMemory;
1111
import org.apache.struts2.ActionSupport;
1212
import org.apache.struts2.Preparable;
13+
import org.apache.struts2.interceptor.parameter.StrutsParameter;
1314

1415
import java.util.ArrayList;
1516
import java.util.Arrays;
@@ -62,6 +63,7 @@ public String input() throws Exception {
6263
return INPUT;
6364
}
6465

66+
@StrutsParameter(depth = 1)
6567
public Person getPersonBean() {
6668
return personBean;
6769
}

preparable-interface/src/main/resources/struts.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
<struts>
77

88
<constant name="struts.devMode" value="true" />
9+
<constant name="struts.allowlist.classes" value="org.apache.struts.edit.model.Person" />
910

1011
<package name="basicstruts2" extends="struts-default">
11-
12+
<default-action-ref name="index" />
1213
<!-- If no class attribute is specified the framework will assume success and
1314
render the result index.jsp -->
1415
<!-- If no name value for the result node is specified the success value is the default -->

preparable-interface/src/main/webapp/WEB-INF/web.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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">
2+
<web-app id="WebApp_ID" version="6.0"
3+
xmlns="https://jakarta.ee/xml/ns/jakartaee"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd">
36
<display-name>Preparable Interface</display-name>
47
<welcome-file-list>
58
<welcome-file>index.jsp</welcome-file>

0 commit comments

Comments
 (0)