【发布时间】:2020-09-16 10:59:26
【问题描述】:
我想分享一些 SpringMVC 表单操作不可更改的问题解决方案,我在 Internet 上找不到,包括这里。 (可能重复)
但是我几乎是 StackOverflow 的新生,所以我只是在这里问自己并立即回答自己。
// 已经尝试在GitHub issue上公开分享解决方案,我也不能很好用。
// 请求原谅...
我在 Spring MVC 4.3.9 中发现了类似 bug。
当我尝试在 javascript 函数中更改表单标记(方法 get)的操作属性时,
Web 浏览器地址窗口中的 URL 映射(我使用的是 Firefox) 始终键入为操作 + 表单标签内的输入标签的名称。
<form action="mappingInControllerToSend" method="get" id="theForm">
<input type="text" name="test1"/>
</form>
<button onclick="formActionChange()"/>
<!-- blah blah -->
<script>
function formActionChange(){
var theForm = document.getElementById("theForm");
var newParam = "test2";
theForm.action = "mappingInControllerToSend?" + newParam;
}
</script>
<!-- the default value of the 'method' attribute in form tag is "get",
so if you don't write the method attribute at all,
then you are using get method, so getting this same wrong result. -->
在这种情况下,按照书本,我应该连接到 Controller 中的“mappingInControllerToSend?test2” (带参数,test2)。
但我总是连接到 Controller 中的“mappingInControllerToSend?test1” (带参数,test1)。
【问题讨论】:
标签: javascript spring forms model-view-controller action