Skip to content

Commit a26684c

Browse files
committed
Refactor(spring-struts): 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. - Change JSP file encoding to UTF-8.
1 parent c3a4977 commit a26684c

6 files changed

Lines changed: 18 additions & 14 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.apache.struts.edit.model.State;
55
import org.apache.struts.edit.service.EditService;
66
import org.apache.struts2.ActionSupport;
7+
import org.apache.struts2.interceptor.parameter.StrutsParameter;
78

89
import java.util.ArrayList;
910
import java.util.Arrays;
@@ -47,6 +48,7 @@ public String input() throws Exception {
4748
return INPUT;
4849
}
4950

51+
@StrutsParameter(depth = 1)
5052
public Person getPersonBean() {
5153

5254

spring-struts/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.packageNames" value="org.apache.struts.edit.model" />
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 -->

spring-struts/src/main/webapp/WEB-INF/web.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<web-app id="WebApp_ID" version="2.4"
3-
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
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">
56
<display-name>Spring Struts 2</display-name>
67

78
<welcome-file-list>

spring-struts/src/main/webapp/edit.jsp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2-
pageEncoding="ISO-8859-1"%>
1+
<%@ page language="java" contentType="text/html; charset=UTF-8"
2+
pageEncoding="UTF-8"%>
33
<%@ taglib prefix="s" uri="/struts-tags" %>
44
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
55
<html>
66
<head>
77
<s:head />
8-
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
8+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
99
<title>Struts 2 Form Tags - Edit Person</title>
1010

1111
</head>

spring-struts/src/main/webapp/index.jsp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2-
pageEncoding="ISO-8859-1"%>
1+
<%@ page language="java" contentType="text/html; charset=UTF-8"
2+
pageEncoding="UTF-8"%>
33
<%@ taglib prefix="s" uri="/struts-tags" %>
44
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
55
<html>
66
<head>
7-
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
7+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
88
<title>Struts 2 Form Tags - Welcome</title>
99
</head>
1010
<body>

spring-struts/src/main/webapp/thankyou.jsp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
<?xml version="1.0" encoding="ISO-8859-1" ?>
1+
<?xml version="1.0" encoding="UTF-8" ?>
22
<%@ taglib prefix="s" uri="/struts-tags" %>
3-
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
4-
pageEncoding="ISO-8859-1"%>
3+
<%@ page language="java" contentType="text/html; charset=UTF-8"
4+
pageEncoding="UTF-8"%>
55
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
66
<html xmlns="http://www.w3.org/1999/xhtml">
77
<head>
8-
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
8+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
99
<title>Update Successful</title>
1010
</head>
1111
<body>

0 commit comments

Comments
 (0)