我正在使用 Spring + bootstrap 来设置一个 web 应用程序,现在我遇到了一个让我困惑的问题。我使用包含表单的模态提交内容和代码如下
<div class="span4">
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#addNew" role="button">
<span class="glyphicon glyphicon-plus">Add</span>
</button>
<div class="modal fade" id="addNew" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Record something useful for you</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" id="newItem" method="POST">
<div class="form-group">
<label class="control-label col-md-2">Title</label>
<div class="col-md-8">
<input type="text" class="form-control" id="title"></input>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-2">Content</label>
<div class="col-md-8">
<textarea rows="10" class="form-control" id="content"></textarea>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" >Close</button>
<button type="button" class="btn btn-primary" id="NewItemModalSubmit" >Save changes</button>
</div>
</div>
</div>
</div>
</div>
$('#NewItemModalClose').click(function() {
console.log('NewItemModalClose button clicked.');
console.log('title field is ', document.getElementById("title").value);
document.getElementById("title").innerHTML = "";
console.log('title field is ', document.getElementById("title").value);
document.getElementById("content").innerHTML = "";
$("#addNew").modal('toggle');
});
问题是如果我在任何输入字段中输入例如“abc def”,我可以从 Spring 端看到收到“abc+def”,我从控制台打印它是“abc def”发送到网络应用程序。不知道这个“+”是怎么来的。
最佳答案
+
只是 url 编码的空格字符。
The encoding used by default is based on a very early version of the general URI percent-encoding rules, with a number of modifications such as newline normalization and replacing spaces with "+" instead of "%20".
所以根据rfc3986空格字符是 %20
但它仍然被转换为 +
附言我不熟悉 Java,但我认为 this link 可以帮助你。
关于css - 使用 Twitter bootstrap + Spring 在表单字段中插入意外的 "+",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24184484/