From de8c75442f8e6742b77e3eede4d5d1a779e66657 Mon Sep 17 00:00:00 2001 From: fp024 Date: Tue, 15 Apr 2025 21:28:22 +0900 Subject: [PATCH 1/2] Refactor(coding actions): Apply `@StrutsParameter` and update web.xml schema - Apply required `@StrutsParameter` to action setters for Struts 7.0+ compatibility. - Update web.xml to Jakarta EE 10 namespace and Servlet 6.0 schema. --- .../apache/struts/helloworld/action/HelloWorldAction.java | 2 ++ coding-actions/src/main/webapp/WEB-INF/web.xml | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/coding-actions/src/main/java/org/apache/struts/helloworld/action/HelloWorldAction.java b/coding-actions/src/main/java/org/apache/struts/helloworld/action/HelloWorldAction.java index fdd75f72..88d81d06 100644 --- a/coding-actions/src/main/java/org/apache/struts/helloworld/action/HelloWorldAction.java +++ b/coding-actions/src/main/java/org/apache/struts/helloworld/action/HelloWorldAction.java @@ -2,6 +2,7 @@ import org.apache.struts.helloworld.model.MessageStore; import org.apache.struts2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** * Acts as a Struts 2 controller that responds @@ -33,6 +34,7 @@ public String getUserName() { return userName; } + @StrutsParameter public void setUserName(String userName) { this.userName = userName; } diff --git a/coding-actions/src/main/webapp/WEB-INF/web.xml b/coding-actions/src/main/webapp/WEB-INF/web.xml index c698d2bc..03377bb1 100644 --- a/coding-actions/src/main/webapp/WEB-INF/web.xml +++ b/coding-actions/src/main/webapp/WEB-INF/web.xml @@ -1,5 +1,8 @@ - + Coding Actions index.jsp From d1cb5d5e2b0e2011f8ebdbb6b878423ec012ab3a Mon Sep 17 00:00:00 2001 From: fp024 Date: Tue, 15 Apr 2025 22:47:07 +0900 Subject: [PATCH 2/2] Refactor(exception-handling): Improve compatibility and fix access issues - Apply `@StrutsParameter` annotations to action setters for Struts 7.0+ compatibility. - Update `web.xml` to use Jakarta EE 10 namespace and Servlet 6.0 schema. - Fix direct JSP access issues for `registerForm` and `index` by routing through actions. - Add missing `struts2-config-browser-plugin` dependency to resolve runtime errors. --- exception-handling/pom.xml | 7 +++++++ .../helloworld/action/HelloWorldAction.java | 2 ++ .../struts/register/action/Register.java | 2 ++ .../src/main/resources/struts.xml | 7 ++++++- .../src/main/webapp/WEB-INF/web.xml | 19 +++++++++++-------- exception-handling/src/main/webapp/error.jsp | 2 +- exception-handling/src/main/webapp/index.jsp | 2 +- exception-handling/src/main/webapp/login.jsp | 2 +- .../src/main/webapp/securityerror.jsp | 2 +- 9 files changed, 32 insertions(+), 13 deletions(-) diff --git a/exception-handling/pom.xml b/exception-handling/pom.xml index b07f43b5..5333dce1 100644 --- a/exception-handling/pom.xml +++ b/exception-handling/pom.xml @@ -15,6 +15,13 @@ war + + + org.apache.struts + struts2-config-browser-plugin + + + exception-handling diff --git a/exception-handling/src/main/java/org/apache/struts/helloworld/action/HelloWorldAction.java b/exception-handling/src/main/java/org/apache/struts/helloworld/action/HelloWorldAction.java index 1547a2ee..eee13a98 100644 --- a/exception-handling/src/main/java/org/apache/struts/helloworld/action/HelloWorldAction.java +++ b/exception-handling/src/main/java/org/apache/struts/helloworld/action/HelloWorldAction.java @@ -2,6 +2,7 @@ import org.apache.struts.helloworld.model.MessageStore; import org.apache.struts2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** * Acts as a Struts 2 controller that responds @@ -37,6 +38,7 @@ public String getUserName() { return userName; } + @StrutsParameter public void setUserName(String userName) { this.userName = userName; } diff --git a/exception-handling/src/main/java/org/apache/struts/register/action/Register.java b/exception-handling/src/main/java/org/apache/struts/register/action/Register.java index 80cc8c07..2da01636 100644 --- a/exception-handling/src/main/java/org/apache/struts/register/action/Register.java +++ b/exception-handling/src/main/java/org/apache/struts/register/action/Register.java @@ -3,6 +3,7 @@ import org.apache.struts.register.exceptions.SecurityBreachException; import org.apache.struts.register.model.Person; import org.apache.struts2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; /** * Acts as a controller to handle actions related to registering a user. @@ -43,6 +44,7 @@ public void throwSecurityException() throws SecurityBreachException { "Security breach exception thrown from throwSecurityException"); } + @StrutsParameter(depth = 1) public Person getPersonBean() { return personBean; diff --git a/exception-handling/src/main/resources/struts.xml b/exception-handling/src/main/resources/struts.xml index fceebbd8..975fe5a5 100644 --- a/exception-handling/src/main/resources/struts.xml +++ b/exception-handling/src/main/resources/struts.xml @@ -69,8 +69,13 @@ /HelloWorld.jsp + + /register.jsp + + - /thankyou.jsp + /thankyou.jsp + /register.jsp diff --git a/exception-handling/src/main/webapp/WEB-INF/web.xml b/exception-handling/src/main/webapp/WEB-INF/web.xml index 58d2ff92..df61ed06 100644 --- a/exception-handling/src/main/webapp/WEB-INF/web.xml +++ b/exception-handling/src/main/webapp/WEB-INF/web.xml @@ -1,11 +1,14 @@ - -Exception Handling - - index.jsp - - - + + + Exception Handling + + index.jsp + + struts2 org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter @@ -15,5 +18,5 @@ struts2 /* - + diff --git a/exception-handling/src/main/webapp/error.jsp b/exception-handling/src/main/webapp/error.jsp index 8fdcfe17..5253216c 100644 --- a/exception-handling/src/main/webapp/error.jsp +++ b/exception-handling/src/main/webapp/error.jsp @@ -17,7 +17,7 @@

Exception Details:

-

Return to the home page.

+

Return to the home page.

diff --git a/exception-handling/src/main/webapp/index.jsp b/exception-handling/src/main/webapp/index.jsp index 44f1fe46..d5f74049 100644 --- a/exception-handling/src/main/webapp/index.jsp +++ b/exception-handling/src/main/webapp/index.jsp @@ -23,7 +23,7 @@ -

Please register for our prize drawing.

+

Please register for our prize drawing.

Cause Exception

Cause Null Pointer Exception

Cause Global Security Exception

diff --git a/exception-handling/src/main/webapp/login.jsp b/exception-handling/src/main/webapp/login.jsp index 37359b44..2186fabf 100644 --- a/exception-handling/src/main/webapp/login.jsp +++ b/exception-handling/src/main/webapp/login.jsp @@ -11,7 +11,7 @@

Please login

-

Return to the home page.

+

Return to the home page.


diff --git a/exception-handling/src/main/webapp/securityerror.jsp b/exception-handling/src/main/webapp/securityerror.jsp index 4eb15228..effcba23 100644 --- a/exception-handling/src/main/webapp/securityerror.jsp +++ b/exception-handling/src/main/webapp/securityerror.jsp @@ -16,6 +16,6 @@

Exception Name:

Exception Details:

-

Return to the home page.

+

Return to the home page.