Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Dec 16, 2008

Encode and Decode URLs Using UTF-8

This tip shows you how to encode and decode your URLs using the UTF-8 character encoding:

import java.net.*;

public class URL_Encoder_Decoder{
	public static void main(String[] args){

      String url = "@sir de caractere@,nr. 1290 'paragraf 3'";
      try{
         String encode_url=URLEncoder.encode(url,"UTF-8");
         String decode_url=URLDecoder.decode(encode_url,"UTF-8");
         System.out.println(url);
         System.out.println(encode_url);  
         System.out.println(decode_url);      
         }catch(java.io.UnsupportedEncodingException e)
              {System.out.println("Error:"+e.getMessage());}            
	}
}

Output:
@sir de caractere@,nr. 1290 'paragraf 3'
%40sir+de+caractere%40%2Cnr.+1290+%27paragraf+3%27
@sir de caractere@,nr. 1290 'paragraf 3'
Leonard Anghel
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap