This is an automated email from the ASF dual-hosted git repository.
lukaszlenart pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/struts.git
The following commit(s) were added to refs/heads/main by this push:
new d27d3fba3 WW-5548 Defines proper request attributes when forwarding or
including final path (#1265)
d27d3fba3 is described below
commit d27d3fba3ae75c2829bd3750c22bec0df6b63100
Author: Lukasz Lenart <[email protected]>
AuthorDate: Mon May 12 14:26:42 2025 +0200
WW-5548 Defines proper request attributes when forwarding or including
final path (#1265)
* WW-5548 Defines proper request attributes when forwarding or including
final path
* Fies typo
Co-authored-by: Copilot <[email protected]>
* WW-5548 Drops RequestDispatcher parameters as they should be defined by
Servlet container
---------
Co-authored-by: Copilot <[email protected]>
---
.../apache/struts2/result/ServletDispatcherResult.java | 12 +++---------
.../struts2/result/ServletDispatcherResultTest.java | 18 ++++++++++++------
2 files changed, 15 insertions(+), 15 deletions(-)
diff --git
a/core/src/main/java/org/apache/struts2/result/ServletDispatcherResult.java
b/core/src/main/java/org/apache/struts2/result/ServletDispatcherResult.java
index feced67bb..a57fd7a9a 100644
--- a/core/src/main/java/org/apache/struts2/result/ServletDispatcherResult.java
+++ b/core/src/main/java/org/apache/struts2/result/ServletDispatcherResult.java
@@ -18,8 +18,6 @@
*/
package org.apache.struts2.result;
-import org.apache.struts2.ActionInvocation;
-import org.apache.struts2.inject.Inject;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@@ -28,9 +26,11 @@ import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import org.apache.struts2.ActionInvocation;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsStatics;
import org.apache.struts2.dispatcher.HttpParameters;
+import org.apache.struts2.inject.Inject;
import org.apache.struts2.url.QueryStringParser;
import java.io.Serial;
@@ -158,13 +158,6 @@ public class ServletDispatcherResult extends
StrutsResultSupport {
//if we are inside an action tag, we always need to do an include
boolean insideActionTag = (Boolean)
ObjectUtils.defaultIfNull(request.getAttribute(StrutsStatics.STRUTS_ACTION_TAG_INVOCATION),
Boolean.FALSE);
- // this should allow integration with third-party view related
frameworks
- if (finalLocation.contains("?")) {
- request.setAttribute(RequestDispatcher.FORWARD_SERVLET_PATH,
finalLocation.substring(0, finalLocation.indexOf('?')));
- } else {
- request.setAttribute(RequestDispatcher.FORWARD_SERVLET_PATH,
finalLocation);
- }
-
// If we're included, then include the view
// Otherwise do forward
// This allow the page to, for example, set content type
@@ -176,6 +169,7 @@ public class ServletDispatcherResult extends
StrutsResultSupport {
dispatcher.forward(request, response);
} else {
LOG.debug("Including location: {}", finalLocation);
+
dispatcher.include(request, response);
}
}
diff --git
a/core/src/test/java/org/apache/struts2/result/ServletDispatcherResultTest.java
b/core/src/test/java/org/apache/struts2/result/ServletDispatcherResultTest.java
index c64c9d76a..12a4796b1 100644
---
a/core/src/test/java/org/apache/struts2/result/ServletDispatcherResultTest.java
+++
b/core/src/test/java/org/apache/struts2/result/ServletDispatcherResultTest.java
@@ -18,7 +18,6 @@
*/
package org.apache.struts2.result;
-import jakarta.servlet.RequestDispatcher;
import org.apache.struts2.ActionContext;
import org.apache.struts2.StrutsInternalTestCase;
import org.apache.struts2.StrutsStatics;
@@ -39,30 +38,38 @@ public class ServletDispatcherResultTest extends
StrutsInternalTestCase implemen
ServletDispatcherResult view = new ServletDispatcherResult();
view.setLocation("foo.jsp");
+ request.setRequestURI("/app/namespace/my.action");
+ request.setContextPath("/app");
+ request.setServletPath("/namespace/my.action");
+ request.setPathInfo(null);
+ request.setQueryString("a=1&b=2");
+
request.setAttribute("struts.actiontag.invocation", null);
request.setAttribute("jakarta.servlet.include.servlet_path", null);
- request.setRequestURI("foo.jsp");
response.setCommitted(Boolean.FALSE);
view.execute(invocation);
assertEquals("foo.jsp", response.getForwardedUrl());
- assertEquals("foo.jsp",
request.getAttribute(RequestDispatcher.FORWARD_SERVLET_PATH));
}
public void testInclude() throws Exception {
ServletDispatcherResult view = new ServletDispatcherResult();
view.setLocation("foo.jsp");
+ request.setRequestURI("/app/namespace/my.action");
+ request.setContextPath("/app");
+ request.setServletPath("/namespace/my.action");
+ request.setPathInfo(null);
+ request.setQueryString("a=1&b=2");
+
request.setAttribute("struts.actiontag.invocation", null);
response.setCommitted(Boolean.TRUE);
- request.setRequestURI("foo.jsp");
view.execute(invocation);
assertEquals("foo.jsp", response.getIncludedUrl());
- assertEquals("foo.jsp",
request.getAttribute(RequestDispatcher.FORWARD_SERVLET_PATH));
}
public void testWithParameter() throws Exception {
@@ -76,7 +83,6 @@ public class ServletDispatcherResultTest extends
StrutsInternalTestCase implemen
// See https://issues.apache.org/jira/browse/WW-5486
assertEquals("1", stack.findString("#parameters.bar"));
- assertEquals("foo.jsp",
request.getAttribute(RequestDispatcher.FORWARD_SERVLET_PATH));
}
@Override