wood burning stoves 2.0
The moose likes Servlets and the fly likes special character for space in URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "special character for space in URL" Watch "special character for space in URL" New topic

special character for space in URL

mark I thomas
Ranch Hand

Joined: Apr 07, 2008
Posts: 86
I know we can use %20 to replace any space character. For example,


But when I use URLEncoder.encode API to encode the parameter values I find it converts space character into "+" instead of %20. When I use "+" to replace the %20 in URL it also works.

So is it true that both "+" and "%20" can be used to replace space char in URL ?
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63351


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
The MIME type of the data being encoded plays a role. It may even be browser dependent - application/x-www-form-urlencoded uses + and properly encoded URIs use %20.

So much trouble in the world -- Bob Marley
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63351

There is nothing improper about using + to encode spaces in URLs.
Howard Watson
Ranch Hand

Joined: Jan 07, 2004
Posts: 56
I've never seen + used in place of %20 in a URL. Decided that since I spent a few minutes thinking on this one to share the references.

RFC 2396: http://www.ietf.org/rfc/rfc2396.txt, sections 2.2 and 3.4.

I visualize URI = URL + URN. I think of the query string as a kind of extension to the URI and not part of my HTTP request, the URN located at URL.

A Google of this topic got several hits to the effect that %20 is interchangeable with + in a URL. They all have a similar example URL.

I finally found this: http://www.w3.org/Addressing/URL/4_URI_Recommentations.html, the section Query strings.

This method was used to make query URIs easier to pass in systems which did not allow spaces.

I agree. Here's the link: http://aspose.com/file-tools
subject: special character for space in URL
It's not a secret anymore!