kumare
asked on
submitting special characters in html form
I have base64 string which i submit using an html form using text box. it has special characters like / , + etc. when i submit the string i receive on the backend here java it gets converted to something like %2F for / . how can avoid this and get the actual value
You can decode it if necessary, but how exactly are you receiving and reading it? Normally it shouldn't need decoding
This is waht URLDecoder will do:
The following rules are applied in the conversion:
The alphanumeric characters "a" through "z", "A" through "Z" and "0" through "9" remain the same.
The special characters ".", "-", "*", and "_" remain the same.
The plus sign "+" is converted into a space character " " .
A sequence of the form "%xy" will be treated as representing a byte where xy is the two-digit hexadecimal representation of the 8 bits. Then, all substrings that contain one or more of these byte sequences consecutively will be replaced by the character(s) whose encoding would result in those consecutive bytes. The encoding scheme used to decode these characters may be specified, or if unspecified, the default encoding of the platform will be used
This is example:
Output:
String shtml = "http://search.barnesandnoble.com/booksearch/first%20book.pdf";
System.out.println(URLDecoder.decode(shtml));
Output:
http://search.barnesandnoble.com/booksearch/first book.pdf
this is better as it will not write deprecated warning:
try{
String shtml = "http://search.barnesandnoble.com/booksearch/first%20book.pdf";
System.out.println(URLDecoder.decode(shtml, "UTF-8"));
}catch(Exception ex){
ex.printStackTrace();
}
http://search.barnesandnoble.com/booksearch/first book.pdf
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
The proper way to do this would normally be the following
a. *en*code the parameter (if sending manually - otherwise the browser will do it)
b. treat it as a normal string at the server end (which will decode it usually)
a. *en*code the parameter (if sending manually - otherwise the browser will do it)
b. treat it as a normal string at the server end (which will decode it usually)
ASKER
I have not tried the solution. but i am accepting this