Meaningless Drivel is fun!
The moose likes Servlets and the fly likes url encoding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "url encoding" Watch "url encoding" New topic

url encoding

Sid Sharama

Joined: Feb 06, 2005
Posts: 11
please explain me what exactly is urlencoding ? when is necessacry ?for ex.
url is
with this i want to pass two paramters
bkid whose value is in a variable bkid1
title whose value is in title1
the usual way is
how to encode this url ?

any help is appreciated
thank you
Paul Wetzel
Ranch Hand

Joined: Nov 02, 1999
Posts: 107
When sending data by a browser (through query string) it is encoded. Here is what encodeing will do:
The ASCII characters 'a' through 'z', 'A' through 'Z', '0' through '9', and ".", "-", "*", "_" remain the same.
The space character ' ' is converted into a plus sign '+'.
All other characters are converted into the 3-character string "%xy", where xy is the two-digit hexadecimal
representation of the lower 8-bits of the character.
I beleive to encode your URL you should do something akin to (if both title1 & bkid1 are vars):
String String = "" + URLEncoder.encode(bkid1) + "&title="+ URLEncoder.encode(title1)
hope this helps
I agree. Here's the link:
subject: url encoding
It's not a secret anymore!