Handle HTML encoded data in Java

Multi tool use
Handle HTML encoded data in Java
I need to dynamically generate some bottoms based on the return of ajax get call
@.getJSON("SearchByName", {"name":searchstring}, function(data){
data = data.replace(/ /g, " ");
var pop = "<p>" + data + "</p><br/><button style="border-radius:
4px;" onclick=getDatabyName("" + data +"")>Load
Locations</button>";
.....
Since the return data may have space so I have to replace all spaces with
When users press the generated bottom to execute getDatabyName
, it calls a Servlet to query a database. However, the query within the Java Servlet returns nothing because the space characters are not properly encoded. I tried to do another replace inside getDatabyName
but still the same. I have ways to work around this but want to know the proper ways (either in Javascript or in Java) to handle this situation.
getDatabyName
getDatabyName
Just edit your question.
– Xufox
Jul 1 at 23:07
1 Answer
1
See this post on how to fix your Java Servlet to decode HTML input:
Java: How to unescape HTML character entities in Java?
PS. Change  
to
in your code.
 
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
data = data.replace(/ /g, " "); missing a semicolon it the original post
– user1941319
Jul 1 at 23:05