Is there a way for a servlet to alter and save a Properties object to a
file on the server?  I want to allow the user to make changes to a
profile (a .properties file on the server), and have them persist on the
server without using a database.


Here are the things I'm looking at:

The java.util.Properties class has methods for loading and saving a
Properties object from a stream, but no setter method for changing
individual properties.

sun.servlet.http.HttpServer::loadProperties()  No saveProperties()
method, plus same problems as above once you get the Properties object.
Also, it's not part of the official Java spec.

There is the java.io.File class.  This usually results in coding some
system-dependent filenames which I would like to avoid if possible.  I
could also scrap the Properties approach and create my own flat-file for
storing profiles.  However, I'd like to use a .properties file, since it
seems naturally suited for the task.

1) java.lang.Class::getResource() is read-only
2) ServletConfig::getServletContext().getResource() is read-only
Jason Hunter's article in JavaWorld mentions using a resource for output
as well.  This is done by taking the resource's URL object, creating a
URLConnection object via URL::openConnection(), invoking
setDoOutput(true) on the URLConnection, and using
URLConnection::getOutputStream() to open an output stream to the
resource.  I haven't tried writing to a .properties file with number 2
above, but trying it with number 1 in some test code resulted in a
"protocol doesn't support output" Exception.  Maybe number 2 would be
able to work by using the ServletClassLoader, and not the
SystemClassLoader--I'm not sure.

java.util.PropertyResourceBundle::getBundle()  read-only

There is a com.sun.server.util.ExProperties class, which is a direct
subclass of java.util.Properties.  It adds functionality for setting
properties, but it's not part of the official Java spec.  If there is a
method of doing this that uses only java.* classes, I would prefer to
use it.

Michael

___________________________________________________________________________
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

Reply via email to