Spring 动态弹簧式动作
我试图在SpringMVC中创建一个表单 我想使用scriplet或其他工具动态设置元素的action属性 我的表格:Spring 动态弹簧式动作,spring,servlets,dynamic,spring-mvc,Spring,Servlets,Dynamic,Spring Mvc,我试图在SpringMVC中创建一个表单 我想使用scriplet或其他工具动态设置元素的action属性 我的表格: <form:form id="myForm" modelAttribute="myFormBean" action="<%=baseUrl%>/myFormControllerPattern" name="myForm"> <fieldset> <table> <tr&
<form:form id="myForm" modelAttribute="myFormBean"
action="<%=baseUrl%>/myFormControllerPattern" name="myForm">
<fieldset>
<table>
<tr>
<th>Name</th>
<td><form:input path="name" /></td>
</tr>
<tr>
<th>Age</th>
<td><form:input path="age"/></td>
</tr>
</table>
</fieldset>
</form:form>
错误:
%>的属性未正确终止
改为使用javascript更改表单操作。将baseUrl作为模型变量传递到spring控制器中,并使用如下javascript函数更改表单操作:
function changeAction () {
var baseUrl = "${baseUrl}";
var form = document.getElementById("myForm");
form.action = baseUrl;
}
希望有帮助。改用javascript更改表单操作。将baseUrl作为模型变量传递到spring控制器中,并使用如下javascript函数更改表单操作:
function changeAction () {
var baseUrl = "${baseUrl}";
var form = document.getElementById("myForm");
form.action = baseUrl;
}
希望有帮助。尝试使用javascript/jQuery技巧:
var curl = document.location.pathname;
curl = curl.substring(0, curl.indexOf(".html"));
第一行将获取您的应用程序地址,然后剪切.html子字符串,从而允许在字符串末尾添加/myFormControllerPattern。尝试使用javascript/jQuery技巧:
var curl = document.location.pathname;
curl = curl.substring(0, curl.indexOf(".html"));
第一行将获取您的应用程序地址,然后剪切.html子字符串,从而允许在字符串末尾添加/myFormControllerPattern。找到了解决方案。多亏了杰利斯 在我的控制器中添加了baseUrl,如下所示:
model.setAttribute("baseUrl",url);
然后在我的JSP表单中使用它:
<form action="${baseUrl}/myFormControllerPattern">
找到了解决办法。多亏了杰利斯 在我的控制器中添加了baseUrl,如下所示:
model.setAttribute("baseUrl",url);
然后在我的JSP表单中使用它:
<form action="${baseUrl}/myFormControllerPattern">
c:url标签可能有用 包含到jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
然后
<form id="myForm" action="<c:url value="/myFormControllerPattern" />" name="myForm">
c:url标签可能有用 包含到jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
然后
<form id="myForm" action="<c:url value="/myFormControllerPattern" />" name="myForm">
谢谢你,jelies,我用你的方法找到了部分解决方案。我在模型中设置了变量,并在url中直接使用为action=${baseUrl}/mypatterns。因此,回答您自己的问题,并接受它!:我很高兴我的回答对你有用。谢谢你,jelies,我用你的方法找到了部分解决方案。我在模型中设置了变量,并在url中直接使用为action=${baseUrl}/mypatterns。因此,回答您自己的问题,并接受它!:我很高兴我的回答对您有用。我得到了解决方案,但是谁能解释一下为什么jsp表达式会出错?什么jsp表达式${baseUrl}/myFormControllerPattern?no.action=/myFormControllerPattern此代码引发了错误。我不确定,但使用scriptlets我相信您必须使用:或类似的东西。我得到了解决方案,但有人能解释为什么jsp表达式引发错误吗?什么jsp表达式${baseUrl}/myFormControllerPattern?no.action=/myFormControllerPattern此代码引发错误。我不确定,但使用scriptlets我相信您必须使用:或类似的东西。