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 value of the counter. The database does not need any set-up. Refer to Configuration.

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.