Updating an ini file in a servlet

V

vincente13

Hi all,

I have this servlet that when it is called, it would update a
config(.ini) file that is bundled with it together as a webapp.

Users are able to enter a new username via a form and the servlet will
be called when the user press the submit button.

However the test.ini is not updated, any ideas to solve this issues?

FileInputStream in = new FileInputStream("test.ini");
Properties p = new Properties();
p.load(in);
p.setProperty("MailUserName", +userName);
p.store(new FileOutputStream("test.ini"), null);

There isn't any issues if an absolute path is given but i would need to
update the test.ini that is within the webapp.

p.store(new FileOutputStream("c:\\test.ini"), null);

Appreciate any advice
 
S

Simon Brooke

in message <[email protected]>,
Hi all,

I have this servlet that when it is called, it would update a
config(.ini) file that is bundled with it together as a webapp.

Users are able to enter a new username via a form and the servlet will
be called when the user press the submit button.

However the test.ini is not updated, any ideas to solve this issues?

You cannot write into a webapp which does not get unpacked. If you are
using Tomcat, check that unpackWARs="true" in the server.xml file.

You can get a directory you can write to within your webapp using the
following:

uploadDirPath =
config.getServletContext( ).getInitParameter( "upload_dir_path" );

File uploadDir =
new File( getServletContext( ).getRealPath( uploadDirPath ) );


if ( !uploadDir.isDirectory( ) || !uploadDir.canWrite( ) )
{
throw new UnavailableException(
"Cannot write to upload directory " +
uploadDirPath );
}
 

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
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top