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:

  • Right click on Web Pages folder
  • Select the Properties option
  • Open the Run tab
  • In Relative URL textbox write the name of the page you want as your default page.
  •  Then click on OK

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

Add a Comment

Your email address will not be published. Required fields are marked *