H All,

I am trying to create a login application using servlets and using sessions for storing the login info. the login info is stored in a hashmap. as the server restarts, the info is lost. So i m trying to write this info in Temp file. So that the info will not lost on server restart.
This is the code

File tempDir = (File)getServletContext().getAttribute("javax.servlet.context.tempdir");

 File tempFile = File.createTempFile(getServletName(), ".tmp", tempDir);

        FileWriter fw= new FileWriter( tempFile );

        fw.write(uname);
        fw.write(pword);

Where uname and pwords are the login info of the user.
When the user logs in for the first time he need to enter username, password and confirm password. And the username and password get store in the hasp map.

The above code creates a temp file, but the login info is lost on server restart. Can anybody help?

Also, when the user clicks browser back button after Logout, he is able to access the 'login required page'. Can somebody help me with logout method?

A code snippet will be most highly appreciated.

Thanks

Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

Stupid idea, and wrong on some many counts I don't even know where to start.

1) you're creating one potential mess of a security breach by writing cleartext passwords to an open directory on a harddisk
2) you're assuming the temp dir isn't cleared regularly. This is a bad assumption
3) you're assuming you're even allowed to write to that location from your servlet. That too is a bad assumption
4) you're assuming temp files are retained on application shutdown. That too is a bad assumption
5) that should be enough for now. Your entire idea is completely and utterly flawed, start from scratch.

This article has been dead for over six months. Start a new discussion instead.