Whenever the '+' symbol is added in the text box in the jsp form and submitted using ajax, the + symbol is missing when seen using System.out.println() from the spring controller.i.e. a blank space is created in its place.
Could anyone tell me why it is happening?
For example:
When I enter
a + b - c
in the sql text box of the form(or the id text box), then it gets printed like
a b - c
query.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Query Insertion</title>
<!-- ajax -->
<script type="text/javascript">
function addQuery() {
var id = document.getElementById("id").value;
var sql = document.getElementById("sql").value;
$.ajax({
type : "POST",
contentType : "text/plain",
url : "addQueryAjax?id=" + id + "&sql=" + sql,
dataType : 'text',
timeout : 100000,
success : function(data) {
console.log("SUCCESS: ", data);
},
error : function(e) {
console.log("ERROR: ", e);
},
done : function(e) {
console.log("DONE");
}
});
document.getElementById("addButton").disabled = true;
}
</script>
<!-- end ajax -->
</head>
<body>
<div align="center">
<div style="width: 650px;">
<form:form class="form-horizontal" method="POST"
modelAttribute="queryBean" action="addQuery">
<div class="form-group form-group-sm">
<label for="id" class="col-sm-2 control-label">Id</label>
<div class="col-sm-10">
<form:input type="text" class="form-control" id="id"
placeholder="id" required="required" autofocus="autofocus"
path="id" />
</div>
</div>
<div class="form-group form-group-sm">
<label for="sql" class="col-sm-2 control-label">sql</label>
<div class="col-sm-10">
<form:input type="text" class="form-control" id="sql"
placeholder="sql" required="required" path="sql" />
</div>
</div>
<div class="form-group form-group-sm">
<div class="col-sm-1">
<input type="button" class="btn btn-primary btn-xs" value="Add"
onclick="addQuery();" id="addButton">
</div>
</div>
</form:form>
</div>
</div>
</body>
</html>
AddQuery.java:
@RequestMapping(value = "/addQueryAjax")
public @ResponseBody String addQueryAjax(@ModelAttribute("queryBean") QueryBean queryBean) {
System.out.println("In controller Method: Query Bean = " + queryBean);
System.out.println("Id = " + queryBean.getId());
System.out.println("sql " + queryBean.getSql());
return "Query Added Successfully!!!";
}
May I know what the reason is for this behavior?