On Tue, 15 Jun 1999, John Burns wrote:
> >I am sending some parameters in the URL which contain values with
> >spaces and ampersands etc, in Netscape the parameters are not
> >properly being transmitted or some problem like that, I tried to
> >encode the URL using java.net.URLEncoder.urlEncode method, but with
> >the encoded url Netscape says that it cannot find the requested url
> >...
>
> URLEncoder.encode encodes the entire document. I think you just want
This is not correct -- URLEncoder.encode takes a string, which it
encodes. So it only encodes what you give it.
> to encode your parameters( Netscape Navigator does choke on spaces
I believe this is correct -- the query string is the only part of the
URL you want to encode, and since the parameter names should not need
to be encoded, you can encode just the parameter values (besides, you
don't want to encode the '&'s between name/value pairs). So you want
to go through all the parameters, building the query string with an
initial '?', then the first parameter name, then a '=', then the first
parameter value encoded, then a '&', then the second parameter name,
than a '=', then the second parameter value encoded, etc.
Perhaps the original poster's problem is that they are encoding too
much of the URL.
BTW, I don't think the browser (Navigator) will choke on such spaces,
it's just that the query string won't be interpreted properly. Also,
on the server side, it's not the web server itself that does the
decoding, it's the application that's reading them -- e.g. CGI or
servlets (the servlet engine usually does it, making the resulting
name/value pair available via getParameter et al).
> in URL parameters). Just use a StringBuffer object to replace all
> occurrences of a space in your parameters with the ASCII hex
> representation, "%20". When you get it back, it will be translated
[ ... ]
As I think someone mentioned, the convention when encoding URLs is to
change each ' ' to a '+' (although "%20" should work also). However,
I would recommend using URLEncoder.encode, because it's there, it's
standard, and you don't have to put this code everywhere you need it.
Milt Epstein
Research Programmer
Software/Systems Development Group
Computing and Communications Services Office (CCSO)
University of Illinois at Urbana-Champaign (UIUC)
[EMAIL PROTECTED]
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html