Java URL Encode encode(String s)

Here you can find the source of encode(String s)

Description

URL encoding.

License

Apache License

Parameter

Parameter Description
s a string to be URL-encoded

Return

URL encoding of s using character encoding UTF-8; null if s is null.

Declaration

public static final String encode(String s) 

Method Source Code

//package com.java2s;

import java.io.UnsupportedEncodingException;

import java.net.URLEncoder;

public class Main {
    /**//from  w w  w .j av a2 s . c o m
     * URL encoding.
     * @param s a string to be URL-encoded
     * @return URL encoding of s using character encoding UTF-8; null if s is null.
     */
    public static final String encode(String s) {
        try {
            if (s != null)
                return URLEncoder.encode(s, "UTF-8");
            else
                return s;
        } catch (UnsupportedEncodingException e) {
            // Java Spec requires UTF-8 be in all Java environments, so this should not happen
            return s;
        }
    }
}

Related

  1. encode(String s)
  2. encode(String s)
  3. encode(String s)
  4. encode(String s)
  5. encode(String s)
  6. encode(String s, String enc)
  7. encode(String s, String encoding)
  8. encode(String source)
  9. encode(String src, String srcCode, String destCode)