这个功能很简单,但是想起来很方便,很久没用忘记了又会很麻烦,所以做一个记录
count.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %> <html> <head> <title>Title</title> </head> <body> <% String pageName=request.getParameter("pageName"); Integer count=(Integer)application.getAttribute(pageName); if (count==null){ count=new Integer(0); } count =new Integer(count.intValue()+1); application.setAttribute(pageName,count); out.println("页面"+pageName+"的访问次数:"+count); %> </body> </html>
page1.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<jsp:include page="count.jsp">
<jsp:param name="pageName" value="page1"/>
</jsp:include>
</body>
</html>