users@glassfish.java.net

Re: java.net.URLEncoder class question

From: Oleksiy Stashok <oleksiy.stashok_at_oracle.com>
Date: Tue, 24 May 2011 17:50:10 +0200

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
>
>
>