betweenGo

Encode URI

by on Mar.17, 2009, under Java SE

To encode an URI you can simply use Java’s URLEncoder’s encode method which has been available since JDK 1.4.

String encodedUri;
  try {
    encodedUri = URLEncoder.encode(uri, "UTF-8");
  }
  catch (UnsupportedEncodingException exc) {
    // this should never happen
    logger.warn("UTF-8 is not a supported encoding?  Not encoding for now...", exc);
    encodedUri = uri;
  }


Share

Related posts:

  1. URLEncoder.encode is Deprecated So What Do I Use for Encoding?
  2. JSTL for current URI
  3. Sleep
  4. Unit Test for Threaded Logging
  5. Accessing the class from a static method which the class owns

:

Leave a Reply

 

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!