Java Server Page

JSP Projects

JSP Project

adplus-dvertising
Write a program that display Session tracking
Previous Home Next
Save that program as a session.jsp

In this program two condition define first, when counter at zero if condition is execute than after refresh the page counter have some value (counter increment) then else condition execute until the browser not close

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.io.*;" %>
<%@page import="javax.servlet.http.*;" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<%--
  save as a session.jsp
   This program contain session tracking.
--%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>R4R Tech Soft</title>
    </head>
    <body>
        <h1>Hello R4R Tech Soft! Session Tracking</h1>
        <%!  String sitename = "www.r4r.co.in"; %>
         Website visit of the day:
                 <%= sitename %>
	       <%
            //Create a session variable - "visit";
             Integer visit = (Integer) session.getAttribute("visit");

           /*  First time when page is load,if codition operate
           *  print this statement, because counter at initial is zero *\
            if (visit == null) {
                visit = new Integer(0);
                session.setAttribute("visit", visit);

                out.println("<BR><BR>Welcome visiter: " + sitename 
+" welcome you" );
              /*After counter have some value(<0)
              * else condition operate & print that statement */
            } else {
                visit = new Integer(visit.intValue() + 1);
                session.setAttribute("visit", visit);
                out.println("<BR><BR> No. of time Website visit: " 
+ visit + "time");
            }
        %>
    </body>
</html>
Output:

First, when counter is in initial condition at zero value, if condition execute.

Now refresh that page to increment counter value, than else condition execute.

Previous Home Next