Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POST Method replacing the '+' characters

Hei. I am using the POST method for sending some information from a JSP to a Servlet. I cannot understand why when I send through the POST method a "+" character, it will be replace with a space character. Example: when I type the following String: 4+5 -> the Servlet will return 4 5; it replaces all the "+" signs. How can I fix this thing? I really need the "+" characters to be visible because after that I need to evaluate the expressions .

like image 852
Steffi Avatar asked May 26 '26 14:05

Steffi


2 Answers

Form variables are sent URL encoded. The "+" plus character is (one) URL encoding of a space.

See also: AJAX POST and Plus Sign ( + ) -- How to Encode?

If you want to send a literal plus sign, you would need to URL encode it either through Javascript or hard-coded "%2B".

like image 191
wrschneider Avatar answered May 30 '26 05:05

wrschneider


You need to URLEncode your data before sending it to the server. The server is trying to decode unencoded data -- the result is that + is decoded to a space.

like image 39
Travis Webb Avatar answered May 30 '26 05:05

Travis Webb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!