Skip to content

Commit bc71082

Browse files
committed
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`.
1 parent 4647a1a commit bc71082

5 files changed

Lines changed: 14 additions & 5 deletions

File tree

wildcard-method-selection/src/main/java/org/apache/struts/tutorials/wildcardmethod/action/PersonAction.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.apache.struts.tutorials.wildcardmethod.model.Person;
66
import org.apache.struts.tutorials.wildcardmethod.service.PersonService;
77
import org.apache.struts2.ActionSupport;
8+
import org.apache.struts2.interceptor.parameter.StrutsParameter;
89

910
import java.util.List;
1011

@@ -68,7 +69,7 @@ public String delete() {
6869
return SUCCESS;
6970
}
7071

71-
72+
@StrutsParameter(depth = 1)
7273
public Person getPerson() {
7374
return person;
7475
}
@@ -93,7 +94,7 @@ public int getId() {
9394
return id;
9495
}
9596

96-
97+
@StrutsParameter
9798
public void setId(int id) {
9899
this.id = id;
99100
}

wildcard-method-selection/src/main/resources/struts.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77

88
<constant name="struts.devMode" value="false" />
99
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
10+
<constant name="struts.allowlist.packageNames" value="org.apache.struts.tutorials.wildcardmethod.model" />
1011

1112
<package name="wildcardmethodexample" extends="struts-default">
1213

14+
<default-action-ref name="index" />
15+
<action name="index">
16+
<result>index.jsp</result>
17+
</action>
1318
<!-- Whatever value is before Person for the name of
1419
the action will be the name of the method to call in
1520
class PersonAction. For example action createPerson

wildcard-method-selection/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>Wildcard_Method_Struts2_Mvn</display-name>
47

58
<welcome-file-list>

wildcard-method-selection/src/main/webapp/input.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%@ page language="java" pageEncoding="ISO-8859-1" %>
1+
<%@ page language="java" pageEncoding="UTF-8" %>
22
<%
33
String path = request.getContextPath();
44
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

wildcard-method-selection/src/main/webapp/view.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%@ page language="java" pageEncoding="ISO-8859-1" %>
1+
<%@ page language="java" pageEncoding="UTF-8" %>
22
<%
33
String path = request.getContextPath();
44
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

0 commit comments

Comments
 (0)