HitCounter Plugin II#
A hit counter plugin that:- Uses a database to store the hits in
- Is fully configurable from the jspwiki.properties file
- Works with multiple installed JSPWikis
Installation #
- Download the HitCounter.jar file to your machine and copy it into the webapps/<jspwikiwebapp>/WEB-INF/lib directory
- Likewise install any database JAR files you need according to the parameters in a jspwiki.properties files you're about to add
- Changed the jspwiki.properties file in the WEB-INF directory (see below)
- Restart Tomcat (or just the webapp if you prefer)
Configuration#
You need to include something like the following in the jspwiki file############################### # HitCounter plugin com.inexas.jspwikiplugins.HitCounter.DbDriver=org.hsqldb.jdbcDriver com.inexas.jspwikiplugins.HitCounter.DbUrl=jdbc:hsqldb:mem:processlab com.inexas.jspwikiplugins.HitCounter.DbUser=sa com.inexas.jspwikiplugins.HitCounter.DbPassword= com.inexas.jspwikiplugins.HitCounter.TestTableSql=SELECT count(*) FROM hitCount com.inexas.jspwikiplugins.HitCounter.CreateTableSql=CREATE TABLE hitCount(pageKey VARCHAR(256) PRIMARY KEY,pageHits INT NOT NULL) com.inexas.jspwikiplugins.HitCounter.ReadHitCountSql=SELECT pageHits FROM hitCount WHERE pageKey=? com.inexas.jspwikiplugins.HitCounter.InsertHitCountSql=INSERT INTO hitCount(pageKey,pageHits)VALUES(?,?) com.inexas.jspwikiplugins.HitCounter.UpdateHitCountSql=UPDATE hitCount SET pageHits=? WHERE pageKey=?
The SQL is pretty standard so it will work with most databases. I use prepared statements to set the ? values so don't try to change the order of the parameters.
Beware: If you copy the parameters directly from the example above an Hypersonic 'in memory' database is used so the counters will be reset every time Tomcat stops and starts. Install your own database and change the parameters appropriately.
It's a good idea to update the plugin search path too.
jspwiki.plugin.searchPath =com.inexas.jspwikiplugins
In the page#
Here's an example of what you need to add the the page(s) you want hit counters in.
This page has been visited [{com.inexas.jspwikiplugins.HitCounter}] times.
And this page has been visited [{HitCounter}] times and my administrator has update the plugin search path too!
Parameters#
- hide=whatever: If you add a 'hide' parameter the plugin does not generate any HTML but silently updates the database
Bugs and annoyances#
Incorrect counter values.#
The counter actually counts how many times the plugin is called - this may be multiple times per page view for example if you have the Sneak Preview active on the edit page the plugin will be called multiple times.Add new attachment
List of attachments
| Kind | Attachment Name | Size | Version | Date Modified | Author | Change note |
|---|---|---|---|---|---|---|
jar |
HitCounter.jar | 3.3 kB | 1 | 05-Jan-2009 18:19 | Kwhittingham | |
java |
HitCounter.java | 5.7 kB | 1 | 05-Jan-2009 18:19 | Kwhittingham |