Struts / tomcat 5.5 / File problem

  • Thread starter Tom Vercauteren via JavaKB.com
  • Start date
T

Tom Vercauteren via JavaKB.com

Hello,

I'm just starting with struts, with the book : Struts in action.

I use some classes from this book, and in one of them, there is a problem
in my environment. (jdk 1.4.2_08, tomcat 5.5.9, struts 1.0.2)

The application is a simple registerpage, where a user must give in a name,
and twice the same password. The name & pw will be stored in a
propertiesfile on the server.

In one of the classes, we gone get the path to the propertiesfile with
following code :

String file = this.getClass().getClassLoader().getResource
(UserDirectoryFile).getFile();
outputstream = new FileOutputStream(o);

But this isn't working.
The value of file is : "C:/Program%20Files/Apache%20Software%
20Foundation/Tomcat%205.5/webapps/register/WEB-
INF/classes/resources/users.properties"

When i do : file = file.replaceAll("%20", " ");
Then my code works.

Isn't there any other solution to this problem? (where my code can
understand %20 as spaces?)

Thanks in advance,
Tom
 
T

Tom Dyess

Check out the package java.net.URLEncoder for URL encoding/decoding. You
could also reference the file as a relative path from your webroot. I would
recommend this approach for an actual production environment because you
should never use an absolute path. With an absolute path, that path must be
on any server you deploy your webapp on.
 

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

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top