This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have a application which is bundled and gets deployed as a WAR file only.
There is a property file xs.properties which I use to store my login username and password in encrypted format.
I have a passreset servlet which resets the password by encrypting & checking the old password and username and if both matches then it writes the new password and username in encrypted format to the property file xs.properties.
My trouble is how can I replace the xs.properties file with the new one. I dont know how I will be able to give a relative path which will replace the xs.properties file with the new one.
Now its creating the new xs.properties file at "webapps"(Tomcat) instead of ABC/WEB-INF/classes folder.
Can somebody let me know what shall be mine approach to make it store the new file @ ABC/WEB-INF/classes folder.
Below code creates the file @ webapps in Tomcat. In webapps folder my war file is deployed.
ServletContext.getRealPath() can help you locate folder locations within the web app.
I should point out that changing files within the web app is not a great idea. It makes updating and redeployment a nightmare. I'd investigate storing the properties file outside the web app, perhaps identifying its location as a context variable.
You should look at the documentation for the getRealPath method as using it could make your app less portable.
Depending on how your app is deployed, there may or may not be a path to the properties file in your system.
The getRealPath method takes a String argument and returns a String
representation of a file on the local file system to which a path corresponds. The
getPathTranslated method computes the real path of the pathInfo of the request.
In situations where the servlet container cannot determine a valid file path for
these methods, such as when the Web application is executed from an archive, on
a remote file system not accessible locally, or in a database, these methods must