Java URL Encode encode(String input)

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

Description

* Returns a URL encoded String obtained from input, which is assumed to be a String composed of characters in the default charset.

License

Apache License

Parameter

Parameter Description
input A String which has not yet been URL encoded

Return

A URL encoded String

Declaration

public static String encode(String input) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.URLEncoder;

public class Main {
    private static String CHARSET = "UTF-8";

    /** *************************************************************
     * Returns a URL encoded String obtained from input, which is
     * assumed to be a String composed of characters in the default
     * charset.  In most cases, the charset will be UTF-8.
     */*from  www  .  ja  v a 2s  . co  m*/
     * @param input A String which has not yet been URL encoded
     *
     * @return A URL encoded String
     */
    public static String encode(String input) {

        String encoded = input;
        try {
            encoded = URLEncoder.encode(input, getCharset());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return encoded;
    }

    /** *************************************************************
     * Returns a String denoting a character encoding scheme.  The
     * default value is "UTF-8".
     *
     * @return String
     */
    public static String getCharset() {
        return CHARSET;
    }
}

Related

  1. encode(Properties prop)
  2. encode(String _string, String _sEncoding)
  3. encode(String from, String to, String word)
  4. encode(String in)
  5. encode(String input)
  6. encode(String raw)
  7. encode(String s)
  8. encode(String s)
  9. encode(String s)