my dog learned polymorphism
The moose likes HTML, CSS and JavaScript and the fly likes Creating a URL Path String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Creating a URL Path String" Watch "Creating a URL Path String" New topic

Creating a URL Path String

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1562
I am trying to use code to create a URL string to an existing file that is in an HTTP compliant folder. However, if the file name has spaces in it the page displays as a blank page. If I rename the file without spaces it works great. How can I use the file name if it does contain blanks, which I am sure the user will use?
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
A space is an illegal character in an URL.
You need to encode the URL using

More about valid URL formats:
More about URL encoding:
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874

Though spaces should be avaioded in URL, %20 is hexadecimal representation of "space". Meaning for each space character %20 is substituted
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Uh, %20 is just the URL encoded value of a space.

I would add, I now realize that you're posting this in the HTML/JS forum, the JS counterpart of URLEncoder is encodeURI.
I agree. Here's the link:
subject: Creating a URL Path String
It's not a secret anymore!