Page Hit Counter Sample

This sample shows you how to use a Java servlet to count how many times a page was visited.

This sample requires a database to store the counter. If you have not already installed and configured your database for the WebSphere samples, refer to Database Configuration for instructions.

Run this sample


How this sample works:

This sample has:

  • A Java servlet that increments a counter every time it is invoked
    • A Java Server Page (JSP) that invokes the servlet and displays the counter
    • A .servlet file that provides information about the servlet to the WebSphere Application Server

The Application Server processes .jsp files with its JSP 1.0 processor servlet. It handles the <jsp:include ... /> tag as a server-side include, replacing the tag with the variable data generated by the servlet.


How to use this sample on your web page:

You can add this exact tag to any HTML page you have on your site. Rename the HTML file with a .jsp file extension, put the Java .class and .servlet files in the classes folder, publish.... and you're ready to go.