package int_2.servlets.assignments3; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import int_2.servlets.*; import int_2.tools.*; /** Please respect the copyright of this code. It is not allowed to copy this code and use at any circumstances. @author © Fredrik Andersson
This servlet uses code from my home made toolbox that you can find in the folder 8/tools and 8/beans. The toolbox is not ready yet, I have been working for it for a couple of years when I have time. The goal is to get a toolbox of classes so it will be easier to map tasks to use-case-diagram. This servlet prints out the counter from assignment 1a with HTML instead of txt. */ public class SecureFileAccess_3a extends GeneralServlet { public void start(HttpServletRequest request, HttpServletResponse response) throws IOException { String output = createPage("applications/int_2/int_2/templates/code_separation_3a.html", "code_separation_3a"); String counterString = ""; synchronized(this) { try { counterString = FileManager.getStringFor("applications/int_2/int_2/templates/1a.txt"); int counter = Integer.parseInt(counterString); counterString = ""+(++counter); FileManager.writeString("applications/int_2/int_2/templates/1a.txt", counterString, false); } catch(Exception e) { counterString = "1"; FileManager.writeString("applications/int_2/int_2/templates/1a.txt", counterString, false); } } output = TextManager.replaceInString(output, "XXXVISITORSXXX", counterString); printString(output); flush(); } }