Ex No: 16 CHECK USER VISIT USING JSP
Aim: To create a JSP page to count user visit.
Algorithm
Step1: Create a folder “Ex16” to place the JSP file.
Step2: Create file “index.jsp”.
Source Code

index.jsp


<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
<%@ page import="java.lang.String" %>
<%@ page import="java.lang.*" %>
<!DOCTYPE html>
<html>
 <head>
  <title>Visitor Counter</title> 
   <meta charset="UTF-8"> 
 </head>
 <style>
  header {
   text-align:center;
   height: 100px;
   background-color: Peru;
   padding: 10px; 
   border-radius: 10px 10px 0px 0px;
  }
  footer {
   text-align:center;
   font-size: 12px;
   height: 50px;
   line-height: 50px;
   background-color: Peru;
   padding: 10px; 
   border-radius: 10px;  
  }
  section{
   width: auto; 
   border: 2px solid gray;
   padding: 10px; 
   border-radius: 10px;
   margin:5px;
  }
  input{
   border-radius: 5px;
   margin: 5px;
  }
 </style>
 <body>  
  <header>
   <h1>JSP Visitor Counter</h1>  
  </header>  
  <article>
    <section>
    <%
      Integer appCouter=(Integer)application.getAttribute("visitCounter");
      if(appCouter==null)
      {
        appCouter=new Integer(1);
      }
      else
      {
        appCouter=new Integer(appCouter.intValue()+1);
      }
      application.setAttribute("visitCounter",appCouter);
    %>    
     <h3>You are Visitor number <%=appCouter%></h3>
    </section>
  </article>
  <footer>
   Developed by K. Anbarasan
  </footer>
 </body>
</html>
Result: Thus JSP page is created to count user visit.