The following code example demonstrates how to write a Program to Display Hit Counter in JSP.
Here is an example of a JSP program that displays a hit counter:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hit Counter Example</title>
</head>
<body>
<%
Integer hits = (Integer) session.getAttribute("hits");
if (hits == null) {
hits = new Integer(1);
} else {
hits = new Integer(hits.intValue() + 1);
}
session.setAttribute("hits", hits);
%>
<h1>Hit Counter</h1>
<p>This page has been hit <%= hits %> time(s).</p>
</body>
</html>
In this example, the JSP page uses a scriptlet to maintain a hit counter in the user’s session. Each time the JSP page is requested, the scriptlet retrieves the current value of the hit counter from the session, increments it, and stores the updated value back in the session. The updated value is then displayed on the page.
Further Reading
Understanding Enterprise Java Beans
- AI
- Android
- Angular
- ASP.NET
- Augmented Reality
- AWS
- Bioinformatics
- Biometrics
- Blockchain
- Bootstrap
- C
- C#
- C++
- Cloud Computing
- Competitions
- Courses
- CSS
- Cyber Security
- Data Science
- Data Structures and Algorithms
- Data Visualization
- Datafication
- Deep Learning
- DevOps
- Digital Forensic
- Digital Trust
- Digital Twins
- Django
- Docker
- Dot Net Framework
- Drones
- Elasticsearch
- ES6
- Extended Reality
- Flutter and Dart
- Full Stack Development
- Git
- Go
- HTML
- Image Processing
- IoT
- IT
- Java
- JavaScript
- Kotlin
- Latex
- Machine Learning
- MEAN Stack
- MERN Stack
- Microservices
- MongoDB
- NodeJS
- PHP
- Power Bi
- Projects
- Python
- Quantum Computing
- React
- Robotics
- Rust
- Scratch 3.0
- Shell Script
- Smart City
- Software
- Solidity
- SQL
- SQLite
- Tecgnology
- Tkinter
- TypeScript
- VB.NET
- Virtual Reality
- Web Designing
- WebAssembly
- XML