URLEncoder (Apache Tomcat 10.1.48 API Documentation)
Description: declaration: package: org.apache.catalina.util, class: URLEncoder

# Class URLEncoder

java.lang.Object
org.apache.catalina.util.URLEncoder

All Implemented Interfaces:
  `Cloneable`

public final class URLEncoder extends Object implements Cloneable
This class is very similar to the java.net.URLEncoder class. Unfortunately, with java.net.URLEncoder there is no way to specify to the java.net.URLEncoder which characters should NOT be encoded. This code was moved from DefaultServlet.java

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final URLEncoder`
  `DEFAULT`
  `static final URLEncoder`
  `QUERY`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `URLEncoder()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addSafeCharacter(char c)`
  `Object`
  `clone()`
  `String`
  `encode(String path, Charset charset)`
  URL encodes the provided path using the given character set.
  `void`
  `removeSafeCharacter(char c)`
  `void`
  `setEncodeSpaceAsPlus(boolean encodeSpaceAsPlus)`

  ### Methods inherited from class Object

  `equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### DEFAULT

    public static final URLEncoder DEFAULT

  - ### QUERY

    public static final URLEncoder QUERY

- ## Constructor Details

  - ### URLEncoder

    public URLEncoder()

- ## Method Details

  - ### addSafeCharacter

    public void addSafeCharacter(char c)

  - ### removeSafeCharacter

    public void removeSafeCharacter(char c)

  - ### setEncodeSpaceAsPlus

    public void setEncodeSpaceAsPlus(boolean encodeSpaceAsPlus)

  - ### encode

    public String encode(String path, Charset charset)
    URL encodes the provided path using the given character set.
    Parameters:
      `path` - The path to encode
      `charset` - The character set to use to convert the path to bytes
    Returns:
      The encoded path

  - ### clone

    public Object clone()
    Overrides:
      `clone` in class `Object`