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 );


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.


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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.