Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

URL Encoding Problem

843841May 2 2004 — edited May 3 2004
I''m having trouble encoding a URL parameter that contains a file name when creating a URL for links displayed on a HTML page.

Here's the problem desciption:
========================
e.g filename = C:\Documents and Settings\Administrator\abc.xml
(note that the file name can contain both spaces and the Windows forward slash file separator)

Now several links that I create on the HTML page need to this refer this file name. So, I use the URLEncoder.encode(filename, "UTF-8") on the filename and encode it before putting it on the links.

Now I'm oberserving this strange phenomenon. If I encode the fiile name only once i.e,
&filename=C%3A%5CDocuments+and+Settings%5CAdministrator%5Cabc.xml

then, on the web server I get this as:
filename = C:DocumentsandSettingsAdministratorabc.xml (note the slashes are missing)

now, if I encode it twice, i.e,
&primary=C%253A%255CDocuments%2Band%2BSettings%255CAdministrator%255Cabc.xml

then, on the web server I get this correctly:
filename = C:\Documents and Settings\Administrator\abc.xml

I'm not sure where is it getting decoded by itself after the html form is submitted. I'm using Tomcat v4.1 for the web server.

Also, does the servlet request decodes the parameters by itself? I mean even when I get the xml file correctly, I don't use the URLDecoder.decode(...), all I do is a request.getParameter("filename") and I get the decoded xml file, why is that so?

Thanks for any help ...

- gadzoox
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 31 2004
Added on May 2 2004
4 comments
586 views