随笔 - 299  文章 - 0  评论 - 0  阅读 - 6322 

JSP生命周期测试代码:

<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jsp生命周期</title>
</head>
<body>
<%!
//声明变量
private int initCnt = 0;
private int serviceCnt = 0;
private int destroyCnt = 0;
%>
<%!
//初始化方法
public void jspInit(){
initCnt++;
System.out.println("jspInit(): JSP被初始化了"+initCnt+"次");
}
//销毁方法
public void jspDestroy(){
destroyCnt++;
System.out.println("JSP被销毁了"+destroyCnt+"次");
}
%>
<%
serviceCnt++;
System.out.println("Jsp响应了"+serviceCnt+"次");
String initString="初始化次数 : "+initCnt;
String serviceString="响应客户请求次数 : "+serviceCnt;
String destroyString ="销毁次数 : "+destroyCnt;
%>
<h1>结果如下:</h1>
<p><%= initString%></p>
<p><%= serviceString%></p>
<p><%= destroyString%></p>
</body>
</body>
</html>

 

posted on   杨申龙  阅读(5)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
点击右上角即可分享
微信分享提示