Passing a url with blank spaces...

D

danielitob

Hi guys,
i've a terrible problem and i'm not able to find a solution.
I've a jsf application and in my jsp page i need to load a file for an
applet (with param tag).
Until i give to param an url without blank spaces all it's ok.
If i pass
<param name="datfile" value=<%="file:///Documents and Settings/bla bla
bla /"&>>

it can't find the file, because it stops to Documents (the first white
space).

How can i do?
Please help me
 
W

wesley.hall

danielitob said:
Hi guys,
i've a terrible problem and i'm not able to find a solution.
I've a jsf application and in my jsp page i need to load a file for an
applet (with param tag).
Until i give to param an url without blank spaces all it's ok.
If i pass
<param name="datfile" value=<%="file:///Documents and Settings/bla bla
bla /"&>>

it can't find the file, because it stops to Documents (the first white
space).

How can i do?
Please help me

If you really must have spaces in a URL you can do it by replacing the
space character with %20
 
A

Andrew Thompson

danielitob wrote:
....
Until i give to param an url without blank spaces all it's ok.
If i pass
<param name="datfile" value=<%="file:///Documents and Settings/bla bla
bla /"&>>

it can't find the file, because it stops to Documents (the first white
space).

How can i do?

Use URLEncoder.encode(String, String)

Andrew T.
 
S

Steve W. Jackson

"Andrew Thompson said:
danielitob wrote:
...

Use URLEncoder.encode(String, String)

Andrew T.

As I read the comments in the Javadocs, that won't produce the desired
result. It says there that spaces become "+". Am I missing something?

It seems to me that it would be better to have a java.io.File object
referring to the file in question and then use the toURI method, which
will produce a valid "file:" URI that's properly encoded, handling all
spaces and any other characters needing special care.

= Steve =
 
O

Oliver Wong

Steve W. Jackson said:
As I read the comments in the Javadocs, that won't produce the desired
result. It says there that spaces become "+". Am I missing something?

"+" is a valid way to encode spaces in URLs. ("%20" is another way).

- Oliver
 
C

Chris Uppal

Oliver said:
"+" is a valid way to encode spaces in URLs. ("%20" is another way).

I don't think it is. '+' is /interpreted/ in some circumstances, by some
servers, as a space, but it's not an encoding of space in the same sense as %20
is.

-- chris
 
O

Oliver Wong

Chris Uppal said:
I don't think it is. '+' is /interpreted/ in some circumstances, by some
servers, as a space, but it's not an encoding of space in the same sense
as %20
is.

Hmm, I looked through a bunch of RFCs, and they mention '+' as a special
character, but not its purpose with respect to acting as a space. I guess I
just saw a lot of servers encode space as '+', and just assumed that that's
how it's supposed to be done. E.g., a google search for "url encoding"
(without the quotes) will take you to the URL
http://www.google.ca/search?q=url+encoding

- Oliver
 
S

Stefan Ram

Oliver Wong said:
Hmm, I looked through a bunch of RFCs, and they mention '+' as a special
character, but not its purpose with respect to acting as a space. I guess I
just saw a lot of servers encode space as '+', and just assumed that that's
how it's supposed to be done. E.g., a google search for "url encoding"
(without the quotes) will take you to the URL
http://www.google.ca/search?q=url+encoding

Right - for example, I have created a URI

http://www.purl.org/stefan_ram/pub/c++_resources_en
 
T

Thomas Hawtin

Oliver said:
Hmm, I looked through a bunch of RFCs, and they mention '+' as a special
character, but not its purpose with respect to acting as a space. I guess I
just saw a lot of servers encode space as '+', and just assumed that that's
how it's supposed to be done. E.g., a google search for "url encoding"
(without the quotes) will take you to the URL
http://www.google.ca/search?q=url+encoding

+ encodes a space, but only within the query string (right of the ?).
URLs don't have the best syntax in the world.

Tom Hawtin
 
S

Steve W. Jackson

"Chris Uppal said:
I don't think it is. '+' is /interpreted/ in some circumstances, by some
servers, as a space, but it's not an encoding of space in the same sense as
%20
is.

-- chris

I'm in no real position to make a case either way, but it became a
question to me simply because the URLEncoder to which Andrew referred is
described in the Javadocs as a "Utility class for HTML form encoding".

Still, I'm watching and learning...
 
C

Chris Uppal

Thomas said:
+ encodes a space, but only within the query string (right of the ?).
URLs don't have the best syntax in the world.

And only by convention, even there. The interpretation of the query string is
/entirely/ up to the program -- if any -- which sees it. The same is true of
the path part of the URL, of course, but not to quite the same extent. The
query is likely to be interpreted by random code hacked together in anything
from Perl to server-side VB, using unknown and possibly non-standard helper
code for the actual parsing (if any).

Last time I was actively involved in HTTP on the wire, this whole area was an
unpredictable mess. It has probably improved since then (more use of standard
parsing packages, etc); but I don't know by how much.

-- chris
 
L

Lasse Reichstein Nielsen

Oliver Wong said:
"+" is a valid way to encode spaces in URLs. ("%20" is another way).

There is a significant difference.

The "%20" must be decoded by the URL receiver, and that encoding
method is specified as part of the URL specification (RFC 1738,
section 2.2). As such, any application using URLs should understand
it.

The "+" is an encoding traditionally used by web browsers for
submitting form data. This encoding is specified in the HTML standard
(<URL:http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4>).
A receiving application must know that this encoding has been used and
apply the opposite decoding in order to retrieve the real text.

I.e., just putting a "+" into an URL does not mean that it will be
interpreted as a space. Only in the parameters section (after the "?")
is the receiver likely to apply url-decoding to it.

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top