Java URL Encode encode(String str)

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

Description

Encode the specified string.

License

Open Source License

Parameter

Parameter Description
str The string to encode.

Return

The encoded string.

Declaration

private static String encode(String str) 

Method Source Code

//package com.java2s;
/**//w  ww. ja  v  a  2  s.  co  m
 * The Heaton Research Spider Copyright 2007 by Heaton
 * Research, Inc.
 * 
 * HTTP Programming Recipes for Java ISBN: 0-9773206-6-9
 * http://www.heatonresearch.com/articles/series/16/
 * 
 * FormUtility: This class is used to construct responses to
 * HTML forms. The class supports both standard HTML forms,
 * as well as multipart forms.
 * 
 * This class is released under the:
 * GNU Lesser General Public License (LGPL)
 * http://www.gnu.org/copyleft/lesser.html
 * 
 * @author Jeff Heaton
 * @version 1.1
 */

import java.io.*;
import java.net.*;

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

    /**
     * Encode the specified string. This encodes all special
     * characters.
     * 
     * @param str
     *          The string to encode.
     * @return The encoded string.
     */
    private static String encode(String str) {
        try {
            return URLEncoder.encode(str, encode);
        } catch (UnsupportedEncodingException e) {
            return str;
        }
    }
}

Related

  1. encode(String s, String enc)
  2. encode(String s, String encoding)
  3. encode(String source)
  4. encode(String src, String srcCode, String destCode)
  5. encode(String str)
  6. encode(String string)
  7. encode(String strInput)
  8. encode(String text)
  9. encode(String toBeEncoded, String charSet, String defaultReturnValue)