📄
字号:
范例ApplicationObject.jsp源代码:
001<html>
002<head>
003<title>Application对象示例</title>
004</head>
005<body>
006<p align="left"><font size="5">Application对象示例</font></p>
007<hr>
008<%
009 //首先通过getAttribute方法获取数据并赋给变量counter
010 String counter=(String)application.getAttribute("counter");
011 //再来判断Application对象中用于存储计数值是否为空
012
013 if(counter!=null)
014 {
015 //如果不为空的话,并将数据从字符串型转换为整型
016 int int_counter=Integer.parseInt(counter);
017 //并对其值加1
018 int_counter+=1;
019 //将加1后的数值再转化成为字符串类型进行存储
020 String s_counter=Integer.toString(int_counter);
021 application.setAttribute("counter",s_counter);
022 }
023 //如果为空的话,则用setAttribute方法将数值1存储到
024 //application变量名称counter中
025 else
026 {
027 application.setAttribute("counter","1");
028 }
029 out.println("你是第"+counter+"位访问此的朋友!");
030%>
031</body>
032</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -