Redirecting Servlet to Unicode Domains

I'm having trouble sending redirects to a servlet with Unicode URLs.

i.e. consider the following url in Turkish

http: //türkçeisimtescil.com

It works if you paste it into the address bar of the browser. However, it is translated into

http://xn--trkeisimtescil-ijb74a.com

your browser upon your request.

Let's say I have the first URL with UTF8 characters, and I get it successfully from the database. I want to redirect a servlet to this URL.

However, when I just do response.sendRedirect(url); (according to the headers), it redirects me to www.t%1frk%e7eisimtescil.com

I even tried response.sendRedirect("http://www.t\u011Frk\u00E7eisimtescil.com"); (inline coding) and the answer was exactly the same.

Perhaps if I get türkçeisimtescil.com in the headers, the browser will convert it to xn--.. format and it will succeed.

I could not understand where the encoding was broken. Any advice is appreciated.

+6
java redirect servlets character-encoding
source share
2 answers

This is an Internationalized Domain Name (IDN). Its conversion between ASCII and Unicode is specified in RFC 3490 . In Java, you can use java.net.IDN to convert between one and the other. You can use java.net.URL to get the host part from the URL.

 String host = new URL("http://türkçeisimtescil.com").getHost(); String idn = IDN.toASCII(host); String newURL = "http://" + idn; 
+7
source share

solvable.

The IDN class java.net.IDN solves this by getting the ponycode URLs (xn-- ..).

 java.net.IDN.toASCII(url) 

3 answering machines per ftw line :)

0
source share

All Articles