Learning Java Programming Made Easy
Page 1: Hit Counter (jsp page)
/*******hits.jsp*******//
Page 1: Hit Counter (jsp page)
/*******hits.jsp*******//
<%-- Document : hits Created on : Nov 30, 2016, 11:54:25 AM Author : admin --%> <%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
<%
Integer hitsCount = (Integer)application.getAttribute("hitCounter");
if( hitsCount ==null || hitsCount == 0 ){
out.println("first time!");
hitsCount = 1;
}else{
/* return visit */
out.println("Welcome back!");
hitsCount += 1;
}
application.setAttribute("hitCounter", hitsCount);
%>
<p>Total number of visits: <%= hitsCount%></p>
</body>
</html>
/***********************************************************//
Page 2: (jsp file)
/************main.jsp**************/
<%-- Document : main Created on : Nov 30, 2016, 12:04:52 PM Author : admin --%> <%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
<jsp:include page="hits.jsp" flush="true" />
</body>
</html>
No comments:
Post a Comment
Welcome, happy learning