5.3. LOG FILES
69
; this is in the file "logger.servlet"
(let ((logdata (read string from file
(servlet file request "log")
""))
(current entry {[(Date.)]: [(.getRemoteAddr request)]}))
(append to file (servlet file request "log") current entry)
{logger

The list of previous visitors to this site is

[logdata]

Your entry is
[current entry]
}
)
Figure 5.3: A simple log servlet
5.3
log files
In this next example, we show how to create a servlet that generates an entry
in a log file for each time the servlet is visited. The logger servlet in Figure 5.3
is quite similar to the counter servlet above.
We begin by appending the current date and time to the logfile  
logger.servlet_log
Instead of  writing  to the counter file, we  append  to the log file. Then we
read the logfile and store it in the  logdata  variable which we include in the
HTML file sent back to the user.
This servlet uses two new procedures for reading/writing files:
  (read string from file FILE DEFAULT VALUE)   this reads the entire
contents of the file as a string of characters, and if the file does not yet
exist it returns the DEFAULT VALUE instead.
  (append to file FILE VALUE)   this appends the specified VALUE to
the next line of the specified FILE. If the file does not already exist then
it creates it.
Also note that the current entry is created using quasi string notation. We
could just as easily have implemented it using string append as follows
(string append (Date.) ": " (.getRemoteAddr request))
which may even be easier to read in this example.




  

Home

About Services Network Support FAQ Order Contact
 

Tomcat Web Hosting

Our partners:Jsp Web Hosting Unlimited Web Hosting Cheapest Web Hosting  Java Web Hosting Web Templates Best Web Templates PHP Mysql Web Hosting Interland Web Hosting Cheap Web Hosting PHP Web Hosting Tomcat Web Hosting Quality Web Hosting Best Web Hosting  Mac Web Hosting 

Lunarwebhost.net  Business web hosting division of Vision Web Hosting Inc. All rights reserved