Skip to content

Commit 9b2d6a2

Browse files
authored
Merge pull request #1127 from apache/feature/WW-5463-servlet-path
WW-5463 Exposes final location as request attribute FORWARD_SERVLET_PATH
2 parents 08f664c + 24c0e5f commit 9b2d6a2

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

core/src/main/java/org/apache/struts2/result/ServletDispatcherResult.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ public void doExecute(String finalLocation, ActionInvocation invocation) throws
158158
//if we are inside an action tag, we always need to do an include
159159
boolean insideActionTag = (Boolean) ObjectUtils.defaultIfNull(request.getAttribute(StrutsStatics.STRUTS_ACTION_TAG_INVOCATION), Boolean.FALSE);
160160

161+
// this should allow integration with third-party view related frameworks
162+
if (finalLocation.contains("?")) {
163+
request.setAttribute(RequestDispatcher.FORWARD_SERVLET_PATH, finalLocation.substring(0, finalLocation.indexOf('?')));
164+
} else {
165+
request.setAttribute(RequestDispatcher.FORWARD_SERVLET_PATH, finalLocation);
166+
}
167+
161168
// If we're included, then include the view
162169
// Otherwise do forward
163170
// This allow the page to, for example, set content type

core/src/test/java/org/apache/struts2/result/ServletDispatcherResultTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.apache.struts2.result;
2020

21+
import jakarta.servlet.RequestDispatcher;
2122
import org.apache.struts2.ActionContext;
2223
import org.apache.struts2.StrutsInternalTestCase;
2324
import org.apache.struts2.StrutsStatics;
@@ -47,6 +48,7 @@ public void testForward() throws Exception {
4748
view.execute(invocation);
4849

4950
assertEquals("foo.jsp", response.getForwardedUrl());
51+
assertEquals("foo.jsp", request.getAttribute(RequestDispatcher.FORWARD_SERVLET_PATH));
5052
}
5153

5254
public void testInclude() throws Exception {
@@ -60,6 +62,7 @@ public void testInclude() throws Exception {
6062
view.execute(invocation);
6163

6264
assertEquals("foo.jsp", response.getIncludedUrl());
65+
assertEquals("foo.jsp", request.getAttribute(RequestDispatcher.FORWARD_SERVLET_PATH));
6366
}
6467

6568
public void testWithParameter() throws Exception {
@@ -73,6 +76,7 @@ public void testWithParameter() throws Exception {
7376

7477
// See https://issues.apache.org/jira/browse/WW-5486
7578
assertEquals("1", stack.findString("#parameters.bar"));
79+
assertEquals("foo.jsp", request.getAttribute(RequestDispatcher.FORWARD_SERVLET_PATH));
7680
}
7781

7882
@Override

0 commit comments

Comments
 (0)