Brett Ryan opened SPR-16617 and commented
Using the spring jstl form tag attribute servletRelativeAction
with a value that starts with the context path strips off this from the value rendered.
Steps to Reproduce
- Create a new webapp deployed at location
/foo
with a spring MVC context mapped to/
- Create a form JSP using the following content
<%@ page pageEncoding="UTF-8" trimDirectiveWhitespaces="true" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<form:form servletRelativeAction="/foo/my-action" method="POST">
</form:form>
<form:form servletRelativeAction="/bar/my-action" method="POST">
</form:form>
- Create a mapping to the above form and observe the output.
Expected Behavior
Form should render as follows:
<form id="command" action="/foo/foo/my-action" method="POST">
</form>
<form id="command" action="/foo/bar/my-action" method="POST">
</form>
Actual Behavior
Form is actually rendered without the leading context path for the first form entry:
<form id="command" action="/foo/my-action" method="POST">
</form>
<form id="command" action="/foo/bar/my-action" method="POST">
</form>
Workaround
Do not use the spring JSTL form implementation and instead use <c:url value="/"/>
to provide the output context path.
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<form action="<c:url value="/foo/my-action"/>" method="POST">
</form>
Alternatively using the spring <form:form>
implementation use the action
attribute by providing the pageContext's context path:
<form:form action="${pageContext.request.contextPath}/foo/my-action" method="POST">
</form:form>
Affects: 5.0.4
Comment From: snicoll
The Javadoc for servletRelativeAction
states:
Action reference to be appended to the current servlet path.
/foo
shouldn't be added there as it should be the relative action.