Site icon WebArtDeveloper

How to use Application object in JSP page

In this tutorial how to use Application object in JSP page  is shown.

Steps to directly launch a different default page on the browser instead of index.html page:

Code:

Counter.jsp

<%@page contentType=”text/html” pageEncoding=”UTF-8″%>
<%@page import=”java.io.*,java.util.*;” %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
<title>Count Page</title>
</head>
<body>
<%! Integer counter; %>
<%
counter=(Integer)application.getAttribute(“numberOfVisits”);
if(counter==null|| counter==0)
{
counter=1;
}
else
{
counter=counter+1;
}
application.setAttribute(“numberOfVisits”,counter);%>
<h3>Total number of hits to this Page is: <%=counter%></h3>
</body>
</html>

 

https://youtu.be/zaz-EQP4Ruo

Exit mobile version