包括和应用
小博士
2022/11/21 23:31:28
9
IT网络
include指令
语法:<%@ include file=”路径+文件名”%>
把指定的文件包含到当前jsp中。
application(应用的全局变量)
实现用户之间的数据共享
常用方法:
Application.setAttribute(Stirng key,Object value);
Application.getAttribute(String key);




1 <%@page import='java.text.SimpleDateFormat'%>
2 <%@page import='java.util.Date'%>
3 <%@ page language='java' contentType='text/html; charset=utf-8'
4 pageEncoding='utf-8'%>
5 <!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>
6 <html>
7 <head>
8 <meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
9 <title>访问人数</title>
10 </head>
11 <body>
12 <%
13 Integer count=(Integer) application.getAttribute('count');
14 if(count != null){
15 count = count+1;
16 }else{
17 count = 1;
18 }
19 application.setAttribute('count', count);
20 %>
21
22 <%
23 Integer i=(Integer)application.getAttribute('count') ;
24 out.print('统计访问量:目前有'+i+'个人访问本网站');
25 %>
26
27 </body>
28 </html>
示例