css - 使用 Twitter bootstrap + Spring 在表单字段中插入意外的 "+"

标签 css html spring twitter-bootstrap spring-mvc

我正在使用 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">&times;</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 编码的空格字符。

Wikipedia says:

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/

相关文章:

javascript - 树 JavaScript 代码不适用于 Internet Explorer

css - 选项卡式导航任何 slider

html - 使用 CSS 更改第一个 child 的背景

jquery - 在悬停时使用 css 更改基本元素?

html - 着色甚至加高列

java - 如何通过两个线程打印非重复元素?

spring - 基于上下文路径的外部配置

html - 沿顶部对齐单元格中的标签(valign 和 vertical-align 不起作用)

html - 使用 hidden-xs 和 visible-xs 加载相同的内容

java - SpringBoot单元测试不使用Application类的@EnableAutoConfiguration注解