Java URL Encode encode(String _string, String _sEncoding)

Here you can find the source of encode(String _string, String _sEncoding)

Description

Encodes the string into URL format.

License

Open Source License

Parameter

Parameter Description
_string string to encode
_sEncoding character encoding

Return

the encoded string in URL format

Declaration

public final static String encode(String _string, String _sEncoding) 

Method Source Code

//package com.java2s;
/**/*from w w  w. j a va  2  s . c o  m*/
 * PureInfo Force
 * @(#)URLUtil.java   1.0 2005-7-7
 * 
 * Copyright(c) 2004-2005, PureInfo Information Techonlogy Corp. Ltd. 
 * All rights reserved, see the license file.
 * 
 * www.pureinfo.com.cn
 */

import java.net.URLEncoder;

public class Main {
    /**
     * Encodes the string into URL format.
     * 
     * @param _string
     *            string to encode
     * @param _sEncoding
     *            character encoding
     * @return the encoded string in URL format
     */
    public final static String encode(String _string, String _sEncoding) {
        try {
            return URLEncoder.encode(_string, _sEncoding);
        } catch (Exception ex) {
            throw new RuntimeException("failed to encode string into URL format using encoding " + _sEncoding, ex);
        }
    }
}

Related

  1. encode(final String value, final String charset)
  2. encode(HashMap map)
  3. encode(Object parameter)
  4. encode(Object value)
  5. encode(Properties prop)
  6. encode(String from, String to, String word)
  7. encode(String in)
  8. encode(String input)
  9. encode(String input)