[ https://issues.apache.org/jira/browse/WW-5548?focusedWorklogId=968902&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-968902 ]
ASF GitHub Bot logged work on WW-5548: -------------------------------------- Author: ASF GitHub Bot Created on: 08/May/25 06:01 Start Date: 08/May/25 06:01 Worklog Time Spent: 10m Work Description: Copilot commented on code in PR #1265: URL: https://github.com/apache/struts/pull/1265#discussion_r2078946274 ########## core/src/main/java/org/apache/struts2/result/ServletDispatcherResult.java: ########## @@ -173,9 +166,28 @@ public void doExecute(String finalLocation, ActionInvocation invocation) throws request.setAttribute("struts.view_uri", finalLocation); request.setAttribute("struts.request_uri", request.getRequestURI()); + // These attributes are required when forwarding to another servlet, see specification: + // https://jakarta.ee/specifications/servlet/6.0/jakarta-servlet-spec-6.0#forwarded-request-parameters + request.setAttribute(RequestDispatcher.FORWARD_MAPPING, request.getHttpServletMapping()); + request.setAttribute(RequestDispatcher.FORWARD_REQUEST_URI, request.getRequestURI()); + request.setAttribute(RequestDispatcher.FORWARD_CONTEXT_PATH, request.getContextPath()); + request.setAttribute(RequestDispatcher.FORWARD_SERVLET_PATH, request.getServletPath()); + request.setAttribute(RequestDispatcher.FORWARD_PATH_INFO, request.getPathInfo()); + request.setAttribute(RequestDispatcher.FORWARD_QUERY_STRING, request.getQueryString()); + dispatcher.forward(request, response); } else { LOG.debug("Including location: {}", finalLocation); + + // These attributes are required when forwarding to another servlet, see specification: Review Comment: The comment in the include block is misleading; update 'forwarding to another servlet' to 'including another resource' for clarity. ```suggestion // These attributes are required when including another resource, see specification: ``` Issue Time Tracking ------------------- Worklog Id: (was: 968902) Time Spent: 20m (was: 10m) > Request attribute jakarta.servlet.forward.servlet_path incorrectly set by > ServletDispatcherResult breaking sitemesh integration > ------------------------------------------------------------------------------------------------------------------------------- > > Key: WW-5548 > URL: https://issues.apache.org/jira/browse/WW-5548 > Project: Struts 2 > Issue Type: Bug > Components: Dispatch Filter > Affects Versions: 7.0.0 > Reporter: Martin > Assignee: Lukasz Lenart > Priority: Major > Fix For: 7.1.0 > > Time Spent: 20m > Remaining Estimate: 0h > > The servlet request parameter jakarta.servlet.forward.servlet_path has the > following documentation in tomcat: > {noformat} > The name of the request attribute that should be set by the container when > the forward(ServletRequest, ServletResponse) method is called. It provides > the original value of a path-related property of the request. See the chapter > "Forwarded Request Parameters" in the Servlet Specification for details. > {noformat} > Strut's org.apache.struts2.result.ServletDispatcherResult#doExecute method is > breaking this spec in a couple of ways: > # it's setting the parameter to be the path that the request is about to be > _forwarded_ to, not the _original_ path. > # it's setting the parameter itself, when that should be the responsibility > of the container (in this case, Tomcat) when forward() is invoked. > Documentation for jakarta.servlet.forward.servlet_path > https://jakarta.ee/specifications/servlet/6.0/jakarta-servlet-spec-6.0#forwarded-request-parameters > Tomcat container implementation of forward() which is responsible for setting > the parameter > https://github.com/apache/tomcat/blob/99ebd1e375297ad02846322e85d533c61077a7dc/java/org/apache/catalina/core/ApplicationDispatcher.java#L241 > This is breaking integration with other tools which expect the > FORWARD_SERVLET_PATH to be set correctly, such as sitemesh (from version 3.1 > onwards) > {code:xml} > <sitemesh> > .... > <mapping path="/auth/*.action" decorator="/WEB-INF/decorators/main.jsp"/> > .... > </sitemesh> > {code} > Sitemesh now picks up the incorrectly set FORWARD_SERVLET_PATH which in my > case is mapped to a JSP in struts.xml like so > {code:xml} > <struts> > ... > <package name="authoritative links" extends="pkb-default" namespace="/auth" > strict-method-invocation="true"> > <action name="dashboard" class="com.pkb.action.DashboardAction"> > <result name="success">/WEB-INF/view/dashboard.jsp</result> > </action> > ... > {code} > and my decorator is no longer applied, when it was previously. > This behaviour was introduced in WW-5463 -- This message was sent by Atlassian Jira (v8.20.10#820010)