Skip to content

Commit c4007ac

Browse files
committed
WW-5463 Exposes final location as request attribute FORWARD_SERVLET_PATH
1 parent 08f664c commit c4007ac

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ 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+
request.setAttribute(RequestDispatcher.FORWARD_SERVLET_PATH, finalLocation.substring(0, finalLocation.indexOf('?')));
163+
161164
// If we're included, then include the view
162165
// Otherwise do forward
163166
// 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)