Simple:
int count;
String path;
public void init() throws ServletException {
FileReader fr = null;
BufferedReader br = null;
String path = "[path to counting file]";
try{
fr = new FileReader( path);
br = new BufferedReader( fr);
String cnt = br.readLine();
count = Integer.parseInt( cnt);
} catch( FileNotFoundException e){}
catch( IOException e) {}
catch( NumberFormatException e) {}
finally {
try {
if( br !=) br.close();
} catch( IOException) {}
}
}
public void doGet( HttpServletRequest req,
HttpServletResponse res) {
synchronized.this {
count++;
}
}
public void destroy {
FileWriter fw = null;
PrintWrite pw = null;
try {
fw = new FileWriter( path);
pw = new PrintWriter( fw);
pw.println( count);
} catch( IOException e) {}
finally {
try {
if( pw != null) pw.close();
} catch( IOException e) {}
}
}
There ya go!
Mark
-----Original Message-----
From: keithBacon [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 13, 2002 11:30 AM
Give us code for being thread safe then - i always avoided that stuff!
--- "Galbreath, Mark" <[EMAIL PROTECTED]> wrote:
> Just create a thread-safe counter in the constructor
> and write it to a textfile.
>
> Mark
>
> -----Original Message-----
> From: Caoilte O'Connor [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, March 12, 2002 1:21 PM
>
> Hi,
> I need to change my webapp to log the number of hits certain
> actions get and from which session etc etc. Can anyone point me towards
> the "right" way to look at doing this. Ideally I would use Log4J or
> something
> similar, but I'm a bit worried about having to parse lots
> of large text files every time my boss wants a gander (especially if he
> insists on having it done as a jsp page).
>
> I know this isn't strictly struts related, but any stabs at how other
people
> have done *in their struts app* appreciated,
>
> Caoilte
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>