eclipseservletsweb-inf

Where to put text files in an Eclipse Dynamic Web Project


I am building a dynamic web project using Eclipse Oxygen and for testing it I am using Tomcat Server(8.5 version) installed in my own desktop. In the webpage there is a functionality wherein a user presses a button , the contents of the text area are to be written back to a log file, and as I have read it is not possible to access files stored in WEB-INF folder from client, so where to store that log file so that when I make a war file of the project and deploy it on my company's internal server, it works fine.


Solution

  • You can do this based on user input or a configuration. 1. Approach 1: You can have one text input which takes the value to where to store the log file. In the servlet get this as location and create a file and store the text area inputs to this file. Log file location:

    <input type="text" name="logFileLocation" value="">
    
    1. Approach 2: Based on the default configuration By default you can have logFileLocation to "C:\Users\username\productname\logs".

    You can get the current user using below the line.

    String username = System.getProperty("user.name");
    Strin fileLocation = "C:\Users\"+ username + "\productname\logs";
    

    Display a note or message about where logs are saving to the user whenever user clicks to store data to log file. E.g: Successully stored data in C:users/user/productname/logs/abc.log file.