Link to home
Create AccountLog in
Avatar of kumare
kumareFlag for United States of America

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
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

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:
String shtml = "http://search.barnesandnoble.com/booksearch/first%20book.pdf";

        System.out.println(URLDecoder.decode(shtml));
        

Open in new window



Output:

http://search.barnesandnoble.com/booksearch/first book.pdf

Open in new window

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();
            }

Open in new window


http://search.barnesandnoble.com/booksearch/first book.pdf

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
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)
Avatar of kumare

ASKER

I  have not tried the solution. but i am accepting this