1. 程式人生 > >include和application

include和application

網站 文件名 pri color www. span play pan imp

include指令

語法:<%@ include file=”路徑+文件名” %>

把指定的文件包含到當前jsp中。

application(應用的全局變量)

實現用戶之間的數據共享

常用方法:

Application.setAttribute(Stirng key,Object value);

Application.getAttribute(String key);

技術分享技術分享

技術分享
 1 <[email protected] import="java.text.SimpleDateFormat"%>
 2 <[email protected]
/* */ 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> 示例

include和application