Spring MVC,表单动作中的子文件夹 [英] Spring MVC, subfolder in form action
问题描述
我有问题,如何在动作属性中创建uri。
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">
结果,没有项目名称 http:// localhost:8080 / user / reservationTour.html
<form:form action="user/reservationTour.html" method="post" commandName="bookTourForm">
结果,2x链接中的用户 http:// localhost:8080 / ProjectContextTitle / user / user / reservationTour.html
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">
推荐答案
如果您已经在用户目录中,只需要使用相对URL即可:
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">
如果您想使用绝对网址,请使用< c:url> ;
,但不包含在另一个JSP标签的属性中:这是非法的。
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}" ...>
这篇关于Spring MVC,表单动作中的子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!