Java URL parameter replaces% 20 with space

On my web page, when the form is submitted with the space entered in the text field, it is read as% 20 in the backend java code instead of space. I can replace% 20 back with "" in the backend, but I think this is the wrong approach and this could happen anywhere in the application.

Is there a better way to handle this in front when submitting a form?

+5
source share
3 answers

There is nothing wrong with that. This is how characters are escaped in the url. You should use it URLDecoder, which is especially appropriate because, despite its name, it decodes application/x-www-form-urlencoded:

String decoded = URLDecoder.decode(queryString, "UTF-8");

/, URL, & =, ( null).

, URL- URI, getQuery(), .

API , , , getParameterMap().

+17
 try {
         String result = URLDecoder.decode(urlString, "UTF-8");
     } catch (UnsupportedEncodingException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
     }
+4
source

All Articles