wood burning stoves 2.0*
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: 1393
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 java.net.URLEncoder.

More about valid URL formats: http://www.ietf.org/rfc/rfc1738.txt
More about URL encoding: http://www.w3schools.com/TAGS/ref_urlencode.asp
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: http://aspose.com/file-tools
subject: Creating a URL Path String
Similar Threads
JSP URL problem
Wierd File Acess Error.
Passing variables from one JSP to another
URL Encode
Runtime.getRuntime() and XP directory name spaces