Tomcat 服务器 B/S 浏览器/服务器 C/S 客户端/服务器
![初识Web(一) - 风一样的少年 - 风一样的少年](http://img0.ph.126.net/g06BgBx5QwpXbKD_7H9U8g==/6631853916513936483.png)
URI :大 广 /项目名 URL: 小 http://localhost:8080/项目名/页面
![初识Web(一) - 风一样的少年 - 风一样的少年](http://img0.ph.126.net/yyO-Ws1NIITvgvZxH9dSvg==/6632056226653449948.png)
![初识Web(一) - 风一样的少年 - 风一样的少年](http://img2.ph.126.net/079SvxnkUxjhugXqYz0yjA==/6632083714444144586.png)
![初识Web(一) - 风一样的少年 - 风一样的少年](http://img1.ph.126.net/PILpeYaS1FtDVfoyZsNAng==/6632084813955772351.png)
![初识Web(一) - 风一样的少年 - 风一样的少年](http://img1.ph.126.net/9oajiZBtdwJQrxsg0fNHlA==/6632167277327853634.png)
![初识Web(一) - 风一样的少年 - 风一样的少年](http://img0.ph.126.net/B4h3wzxzEh1k1iwvrql8jw==/6631846219932548775.png)
JSP的生命周期
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<%!//全局变量
int initNum = 0;
int serviceNum = 0;
int destroyNum = 0;
%>
int initNum = 0;
int serviceNum = 0;
int destroyNum = 0;
%>
<%!//书写两个方法
public void jspInit() {
initNum++;
System.out.println("jspInit()初始化执行了" + initNum + "次");
}
public void jspInit() {
initNum++;
System.out.println("jspInit()初始化执行了" + initNum + "次");
}
public void jspDestroy() {
destroyNum++;
System.out.println("jspdestroy()销毁执行了" + destroyNum + "次");
}
%>
destroyNum++;
System.out.println("jspdestroy()销毁执行了" + destroyNum + "次");
}
%>
<%
//只要是没有! 所有的内容都会在service中
//service()
serviceNum++;
System.out.println("jspDestroy()销毁执行了" + destroyNum + "次");
//只要是没有! 所有的内容都会在service中
//service()
serviceNum++;
System.out.println("jspDestroy()销毁执行了" + destroyNum + "次");
String sayInit = "初始化次数" + initNum;
String sayService = "执行次数" + serviceNum;
String sayDestroy = "销毁次数" + destroyNum;
%>
String sayService = "执行次数" + serviceNum;
String sayDestroy = "销毁次数" + destroyNum;
%>
<%=sayInit%><br/>
<%=sayService%><br/>
<%=sayDestroy%><br/>
</body>
</html>
<%=sayService%><br/>
<%=sayDestroy%><br/>
</body>
</html>
![初识Web(一) - 风一样的少年 - 风一样的少年](http://img1.ph.126.net/sMJrYhsr4Awj597WAGDV8A==/6631944076467415027.png)
![初识Web(一) - 风一样的少年 - 风一样的少年](http://img1.ph.126.net/lTNEi1LTp3-pbpYXXHQl5w==/6632160680258090593.png)
![初识Web(一) - 风一样的少年 - 风一样的少年](http://img0.ph.126.net/MsW0mjevxLvi70zxjx7eEg==/6632018843258103225.png)
![初识Web(一) - 风一样的少年 - 风一样的少年](http://img2.ph.126.net/3x-95YY-z2W9AbIoVq0HdA==/6632127694909256561.png)
![初识Web(一) - 风一样的少年 - 风一样的少年](http://img0.ph.126.net/Cx0mMe4cxC7yquy6_E01og==/6631997952537162063.png)
![初识Web(一) - 风一样的少年 - 风一样的少年](http://img1.ph.126.net/8Xa0z7MLBEBeQdWQH8kxZQ==/6632091411025539643.png)