Skip to content

Commit 244fd2e

Browse files
authored
Merge pull request #446 from fp024/dev-2025-04-15-a
Fixed "coding-actions" and "exception-handling" examples
2 parents cf09a9e + d1cb5d5 commit 244fd2e

11 files changed

Lines changed: 38 additions & 14 deletions

File tree

coding-actions/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
@@ -33,6 +34,7 @@ public String getUserName() {
3334
return userName;
3435
}
3536

37+
@StrutsParameter
3638
public void setUserName(String userName) {
3739
this.userName = userName;
3840
}

coding-actions/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>Coding Actions</display-name>
47
<welcome-file-list>
58
<welcome-file>index.jsp</welcome-file>

exception-handling/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515

1616
<packaging>war</packaging>
1717

18+
<dependencies>
19+
<dependency>
20+
<groupId>org.apache.struts</groupId>
21+
<artifactId>struts2-config-browser-plugin</artifactId>
22+
</dependency>
23+
</dependencies>
24+
1825
<build>
1926
<finalName>exception-handling</finalName>
2027
<plugins>

exception-handling/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
}

exception-handling/src/main/java/org/apache/struts/register/action/Register.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.apache.struts.register.exceptions.SecurityBreachException;
44
import org.apache.struts.register.model.Person;
55
import org.apache.struts2.ActionSupport;
6+
import org.apache.struts2.interceptor.parameter.StrutsParameter;
67

78
/**
89
* Acts as a controller to handle actions related to registering a user.
@@ -43,6 +44,7 @@ public void throwSecurityException() throws SecurityBreachException {
4344
"Security breach exception thrown from throwSecurityException");
4445
}
4546

47+
@StrutsParameter(depth = 1)
4648
public Person getPersonBean() {
4749

4850
return personBean;

exception-handling/src/main/resources/struts.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,13 @@
6969
<result name="success">/HelloWorld.jsp</result>
7070
</action>
7171

72+
<action name="registerForm">
73+
<result>/register.jsp</result>
74+
</action>
75+
7276
<action name="register" class="org.apache.struts.register.action.Register" method="execute">
73-
<result name="success">/thankyou.jsp</result>
77+
<result name="success">/thankyou.jsp</result>
78+
<result name="input">/register.jsp</result>
7479
</action>
7580

7681
</package>
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
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">
3-
<display-name>Exception Handling</display-name>
4-
<welcome-file-list>
5-
<welcome-file>index.jsp</welcome-file>
6-
</welcome-file-list>
7-
8-
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">
6+
7+
<display-name>Exception Handling</display-name>
8+
<welcome-file-list>
9+
<welcome-file>index.jsp</welcome-file>
10+
</welcome-file-list>
11+
912
<filter>
1013
<filter-name>struts2</filter-name>
1114
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
@@ -15,5 +18,5 @@
1518
<filter-name>struts2</filter-name>
1619
<url-pattern>/*</url-pattern>
1720
</filter-mapping>
18-
21+
1922
</web-app>

exception-handling/src/main/webapp/error.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<h4>Exception Details: <s:property value="exceptionStack"/></h4>
1818

1919

20-
<p><a href="index.jsp">Return to the home page.</a></p>
20+
<p><a href="<s:url action='index' />">Return to the home page.</a></p>
2121
</body>
2222

2323
</html>

exception-handling/src/main/webapp/index.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<s:submit value="Submit"/>
2424
</s:form>
2525

26-
<p><a href="register.jsp">Please register</a> for our prize drawing.</p>
26+
<p><a href='<s:url action="registerForm" />'>Please register</a> for our prize drawing.</p>
2727
<p><a href='<s:url action="causeexception" />'>Cause Exception</a></p>
2828
<p><a href='<s:url action="causenullpointerexception" />'>Cause Null Pointer Exception</a></p>
2929
<p><a href='<s:url action="causesecurityexception" />'>Cause Global Security Exception</a></p>

exception-handling/src/main/webapp/login.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<p>Please login</p>
1313

14-
<p><a href="index.jsp">Return to the home page.</a></p>
14+
<p><a href="<s:url action='index' />">Return to the home page.</a></p>
1515

1616
<hr>
1717

0 commit comments

Comments
 (0)