Skip to content

Commit 3fab6ab

Browse files
committed
Refactor(message-resource): 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. - Changed encoding of JSP and `global_es.properties` files to UTF-8.
1 parent fee2acc commit 3fab6ab

9 files changed

Lines changed: 28 additions & 20 deletions

File tree

message-resource/src/main/java/org/apache/struts/helloworld/action/HelloWorldAction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.apache.struts.helloworld.model.MessageStore;
44
import org.apache.struts2.ActionSupport;
5+
import org.apache.struts2.interceptor.parameter.StrutsParameter;
56

67
/**
78
* Acts as a Struts 2 controller that responds
@@ -37,6 +38,7 @@ public String getUserName() {
3738
return userName;
3839
}
3940

41+
@StrutsParameter
4042
public void setUserName(String userName) {
4143
this.userName = userName;
4244
}

message-resource/src/main/java/org/apache/struts/register/action/Register.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.apache.struts.register.model.Person;
44
import org.apache.struts2.ActionSupport;
5+
import org.apache.struts2.interceptor.parameter.StrutsParameter;
56

67
/**
78
* Acts as a controller to handle actions
@@ -48,7 +49,7 @@ public void validate(){
4849

4950
}
5051

51-
52+
@StrutsParameter(depth = 1)
5253
public Person getPersonBean() {
5354

5455
return personBean;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
contact=Para asistencia, comuníquese <a href='mailto:comuníquese@email.com'>comuníquese@email.com</a>
1+
contact=Para asistencia, comuníquese <a href='mailto:comuníquese@email.com'>comuníquese@email.com</a>

message-resource/src/main/resources/struts.xml

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

88
<constant name="struts.devMode" value="true" />
9-
<constant name="struts.custom.i18n.resources" value="global" />
9+
<constant name="struts.allowlist.classes" value="org.apache.struts.helloworld.model.MessageStore" />
10+
<constant name="struts.custom.i18n.resources" value="global" />
1011

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

14+
<default-action-ref name="index" />
1315
<!-- If no class attribute is specified the framework will assume success and
1416
render the result index.jsp -->
1517
<!-- If no name value for the result node is specified the success value is the default -->

message-resource/src/main/webapp/HelloWorld.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>Hello World!</title>
99
</head>
1010
<body>

message-resource/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>Message Resource</display-name>
47
<welcome-file-list>
58
<welcome-file>index.jsp</welcome-file>

message-resource/src/main/webapp/index.jsp

Lines changed: 5 additions & 5 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>Basic Struts 2 Application - Welcome</title>
99
</head>
1010
<body>
@@ -31,11 +31,11 @@
3131
</s:url>
3232
<p><a href="${registerInputLink}">Please register</a> for our prize drawing.</p>
3333

34-
<h3>Registro español</h3>
34+
<h3>Registro español</h3>
3535
<s:url action="registerInput" var="registerInputLinkES">
3636
<s:param name="request_locale">es</s:param>
3737
</s:url>
38-
<p><a href="${registerInputLinkES}">Por favor, regístrese</a> para nuestro sorteo</p>
38+
<p><a href="${registerInputLinkES}">Por favor, regístrese</a> para nuestro sorteo</p>
3939

4040
<hr />
4141
<s:text name="contact" />

message-resource/src/main/webapp/register.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>Register</title>
1010
<s:head />
1111
</head>

message-resource/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>Registration Successful</title>
1010
</head>
1111
<body>

0 commit comments

Comments
 (0)