问题
I have problem, how to create uri in action attribute. I have to use subfolders as "user", "admin" because I use Spring Security.
<form:form action="/user/reservationTour.html" method="post" commandName="bookTourForm">
Result, no project name http://localhost:8080/user/reservationTour.html
<form:form action="user/reservationTour.html" method="post" commandName="bookTourForm">
Result, 2x user in link http://localhost:8080/ProjectContextTitle/user/user/reservationTour.html
<form:form action="<c:url value="/user/reservationTour.html" />" method="post" commandName="bookTourForm">
Result, exception
org.apache.jasper.JasperException: /jsp/user/reservationTourPage.jsp(7,33) Unterminated <form:form tag
This works fine, but sure not good solution
<form:form action="/ProjectContextName/user/reservationTour.html" method="post" commandName="bookTourForm">
回答1:
If you're already in the user directory, you just need to use a relative URL:
<form:form action="reservationTour.html" method="post" commandName="bookTourForm">
If you want to use an absolute URL, use <c:url>
, but don't include it in the attribute of another JSP tag: that's illegal.
<c:url value="/user/reservationTour.html" var="theAction"/>
<form:form action="${theAction}" ...>
来源:https://stackoverflow.com/questions/9334623/spring-mvc-subfolder-in-form-action