Question

what is the best way for creating a jsp visitor hit counters? is it better to use txt file and save the hit value into a file, or create a table in database??? or use session/cookie to count the users whom have visited the website?

Was it helpful?

Solution

That are a lot of questions. I'll answer them separately.

what is the best way for creating a jsp visitor hit counters?

A Filter which listens on the url-pattern matching the requests of interest. Maybe *.jsp?

is it better to use txt file and save the hit value into a file, or create a table in database???

A database is definitely faster. If you don't have or can't afford one, then live with a text file. Be careful that you don't save it inside the webapplication, but externally elsewhere on the local disk file system. Else it will get lost whenever you redeploy the webapplication.

or use session/cookie to count the users whom have visited the website?

Only use this to count the amount of user-specific visits during the user-specific session. Do not use this to count the sitewide amount of visits or whenever you care the cookie value to be manipulated.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top