Reputation: 586
I'm passing a string, that contains plus signs (+), from jsp page to servlet, but in the servlet, the string has blank spaces instead of "+".
JSP code:
var data = {Certificate:"KgAwIBAgIQQ+1b5xQKgN0HfjIAPy+vdjANBg",Id:10043};
$.ajax({
type: "POST",
url: "Assinatura",
data: 'signStart=' + JSON.stringify(data)
});
Servlet code:
request.getParameter("signStart"); //KgAwIBAgIQQ 1b5xQKgN0HfjIAPy vdjANBg
I know I could replace the spaces on server side, but was wandering if there is a better solution.
Upvotes: 2
Views: 468
Reputation: 213351
You need to encode the string while passing it to Servlet in your ajax request. You can use encodeURIComponent
for that:
$.ajax({
type: "POST",
url: "Assinatura",
data: 'signStart=' + encodeURIComponent(JSON.stringify(data))
});
or you can pass data
as Object, instead of String:
data: {'signStart': JSON.stringify(data)}
Upvotes: 1
Reputation: 2467
Characters like "+" needs to be encoded when passing through URL
Upvotes: 5