Z-AJSP Codes

Find no of Hits Using Jsp

 BACK

Find no of Hits Using Jsp

Hits.jsp

[xml]

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="sample.jsp">
<input type="submit" value="submit">
</form>
</body>
</html>

[/xml]

sample.jsp

[xml]
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h2>Here you can  See the no. of HITS </h2>
<%

try{
out.println((Integer)application.getAttribute("user") + 1);
application.setAttribute("user",(Integer)application.getAttribute("user")+1);
}
catch(NullPointerException e)
{
application.setAttribute("user", new Integer(1));
out.println((Integer)application.getAttribute("user"));
}

%> <form action="hits.jsp">
<input type="submit" value="back">
</form>
</body>
</html>

[/xml]

web.xml

[xml]

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>HitJsp1</display-name>
<welcome-file-list>
<welcome-file>hits.jsp</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>

[/xml]

Output screenshot

          Download sourcecode

BACK