Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL Decode in Java 6 [duplicate]

Tags:

I see that java.net.URLDecoder.decode(String) is deprecated in 6.

I have the following String:

String url ="http://172.20.4.60/jsfweb/cat/%D7%9C%D7%97%D7%9E%D7%99%D7%9D_%D7%A8%D7%92%D7%99%D7%9C%D7%99%D7%9"

How should I decode it in Java 6?

like image 811
danny.lesnik Avatar asked Jun 29 '11 11:06

danny.lesnik


2 Answers

You should use java.net.URI to do this, as the URLDecoder class does x-www-form-urlencoded decoding which is wrong (despite the name, it's for form data).

like image 195
Draemon Avatar answered Sep 28 '22 22:09

Draemon


Now you need to specify the character encoding of your string. Based off the information on the URLDecoder page:

Note: The World Wide Web Consortium Recommendation states that UTF-8 should be used. Not doing so may introduce incompatibilites.

The following should work for you:

java.net.URLDecoder.decode(url, "UTF-8");

Please see Draemon's answer below.

like image 40
Tim Cooper Avatar answered Sep 28 '22 22:09

Tim Cooper