Spring MVC appending context path to form action

2019-02-20 04:04发布

问题:

Was running same code fine under Spring 3.1. Just upgraded to 3.2 and now the following issue occurs:

<form:form id="customerLoginForm" commandName="customerLoginForm" action="/login" name="">

under 3.1 would generate the following HTML:

<form id="customerLoginForm" action="/login" method="post">

now generates:

<form id="customerLoginForm" action="/webapp/login" method="post">

where "webapp" is the context path in Websphere of our webapp.

In the example above, the GET request to /login is successful but returns the improper form action="/webapp/login" (the form submits a POST back to the same URL). So when the form is submitted I get a 404 bad URL error.

Did something change in 3.2? Is there somewhere to tell Spring to ignore the context path? I could go back change all absolute paths to relative paths (e.g., "login" instead of "/login") but I'd prefer not to since there are 20+ forms in my webapp.

回答1:

Sorry it's not a bug, it's a new feature. Please see this jira: Form tag should prepend the contextPath and servletPath if not present

Which apparently got rolled back on 3.2.3. So you might see your code behavior return to normal just by upgrading to latest version