I am trying to pass special characters as querystring in url as part of GET request. I am constructiong that string in javascript function.
var queryString = "list=ABC-48+12&level=first";
Then I append the string to url as part of request which goes to struts action class. In the action class I get the "list" value as "ABC-48 12"
, the "+"
character is not passed.
How to pass special characters in the string as part of url and get back in the java class?
Please let me know.
Thanks.
You should url encode it using the encodeURIComponent
function:
var queryString =
"list=" + encodeURIComponent("ABC-48+12") +
"&level=" + encodeURIComponent("first");
This function will take care of properly encoding your query string parameter values:
list=ABC-48%2B12&level=first
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With