Print. Writernew. File. Writerf. Reader new. File. Readerf. buffered. Reader new. Buffered. Readerfile. Reader. String initial buffered. Reader. read. Line. Integer. parse. Intinitial. Exception ex. if writer null. Reader null. Reader. IOException e. Stack. Trace. return count. Exception. File. Writer file. Writer null. Print. Writer print. Writer null. Writer new. File. WriterFile. Counter. Writer new. Print. Writerfile. Writer. Writer. printlncount. Writer null. Writer. Create a servlet. Right click on your project and select. Enter the following data. Press finish. You could also create a servlet without the wizard. The wizard. creates a Java class. Http. Servlet. adds the servlet. Enter the following code. IOException. importjava. Print. Writer. importjavax. Servlet. Exception. Web. Servlet. importjavax. Http. Servlet. importjavax. Http. Servlet. Request. Http. Servlet. Response. Http. Session. importcom. File. Dao. Web. ServletFile. Counter. publicclass. File. Counterextends Http. Servlet. privatestaticfinallong serial. Version. UID 1. L. File. Dao dao. Overrideprotectedvoid do. GetHttp. Servlet. Request request. Http. Servlet. Response response throws Servlet. Exception, IOException. Http. Session session request. Sessiontrue. session. Max. Inactive. Interval5. Content. Typetextplain. Print. Writer out response. Writer. if session. New. count. This site has been accessed count times. Overridepublicvoid init throws Servlet. Exception. dao new File. Dao. count dao. Count. Exception e. Servlet. Context. An exception occurred in File. Counter, e. thrownew Servlet. ExceptionAn exception occurred in File. Counter. e. get. Message. Exception e. e. Stack. Trace. This code will read the counter from a file on the server and. The servlet will increase the. You application must be deployed to the server and started there. Select your servlet or your project, right click on it and select. Ensure your servlet is selected to run on the server. In case you get the error The Tomcat server configuration at. ServersTomcat v. Server at localhost config is missing. Check. the server for errors., simply delete the existing server. Press the Finish button. If the deployment was successfully you should be able to access your servlet via the following URL http localhost 8. File. Counter. The servlet will return the number of times it was accessed. If you wait 5 seconds and refresh the browser, the number should increase.