1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>Insert title here</title> 8 </head> 9 <body> 10 <% 11 12 String str=application.getInitParameter("test2"); 13 out.print("test2="+str+"<br>"); 14 //模擬計數器 15 //初始化 16 //取出計數器的當前值 17 Object obj=application.getAttribute("count"); 18 if(obj==null) 19 { 20 21 application.setAttribute("count", 1); 22 obj=1; 23 } 24 25 //模擬計數器++(+1)的運行方式 26 //數據轉型,同object轉成數值型 27 long count=Long.parseLong(obj.toString()); 28 count++; 29 //out.print("count="+obj.toString()); 30 out.print("count="+count); 31 //取完之後將新的值在放到裡面繼續疊加運算 32 application.setAttribute("count", count); 33 %> 34 </body> 35 </html>