Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC, subfolder in form action

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 &lt;form:form tag

This works fine, but sure not good solution

<form:form action="/ProjectContextName/user/reservationTour.html" method="post" commandName="bookTourForm">
like image 774
LancerX Avatar asked Nov 22 '25 23:11

LancerX


1 Answers

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}" ...>
like image 105
JB Nizet Avatar answered Nov 25 '25 16:11

JB Nizet