Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring JSTL form tag removes context path if servletRelativeAction starts with context path [SPR-16617] #21158

Open
spring-projects-issues opened this issue Mar 20, 2018 · 0 comments

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Mar 20, 2018

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

  1. Create a new webapp deployed at location /foo with a spring MVC context mapped to /
  2. Create a form JSP using the following content ```html
    <%@ 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>
1. Create a mapping to the above form and observe the output.

# Expected Behavior

Form should render as follows:

```html 
<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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant