java.net.URLEncoder
class provides 'encode' method to encode url.
public static String
encode(String s, String encodingScheme)
Encode
the url using given encoding scheme.
Every
standard Java implementation must support below encoding schemes.
1. US-ASCII
2. ISO-8859-1
3. UTF-8
4. UTF-16BE
5. UTF-16LE
6. UTF-16
'java.nio.charset.Charset'
class provides 'isSupported' method to check whether given character encoding
is supported by your Java implementation or not.
Below
program encodes a url and print the encoded url to the console.
package com.sample; import java.io.UnsupportedEncodingException; public class URLEncoder { public static void main(String args[]) throws UnsupportedEncodingException { String encodedURL = java.net.URLEncoder.encode("https://self-learning-java-tutorial.blogspot.com/2014/09/servlets.html", "UTF-8"); System.out.println("encodedURL : " + encodedURL); } }
Output
encodedURL : http%3A%2F%2Fself-learning-java-tutorial.blogspot.in%2F2014%2F09%2Fservlets.html
You
can refer below link, to know all the encoding schemes supported by Java.
Miscellaneous
No comments:
Post a Comment