Spring MVC, subfolder in form action

陌路散爱 提交于 2019-12-11 01:36:42

问题


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">

回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!