users@glassfish.java.net

Re: java.net.URLEncoder class question

From: Shing Wai Chan <shing.wai.chan_at_oracle.com>
Date: Tue, 24 May 2011 10:10:48 -0700

One can find more details in section 2.2 and 3.3 of
http://www.ietf.org/rfc/rfc2396.txt.

On 5/24/11 8:50 AM, Oleksiy Stashok wrote:
> Hi,
>
> pls. try:
> new URI(null, null, "Bello Terry_ Snow#605B.jpg", null).toString();
>
> URLEncoder.encode(...) supposed to be used for HTML forms encoding
> (see javadoc).
>
> WBR.
>
> On 05/24/2011 04:06 AM, emiddio-frontier wrote:
>> i have a filename "Bello Terry_ Snow#605B.jpg" -- not counting the '
>> " ' chars;
>>
>> the name contains a blanks, and and '#' characters.
>>
>> i want to serve it over http with a servlet.
>>
>> when i use URLEncoder.encode(filename, "UTF-8") the result is
>> "Bello+Terry_+Snow%23605B.jpg"
>>
>> that String is not accepted/decoded properly by the standard default
>> glassfish v301 servlet --
>> it refuses to serve up the file. -- yet it contains the ' + ' chars
>> that i read are to be used
>> to represent blanks.
>>
>> when the blanks are converted to %20 -- ie the resultant String is
>> "Bello%20Terry_%20Snow%23605B.jpg" -- the file is served up.
>>
>> What is going on here ?; are ' + ' no longer the way to encode spaces ?
>>
>> What method of which class can i use to generate the proper encoding ?
>>
>> thanks
>>
>> gary
>>
>>
>>
>