课堂案例-使用声明
案例学习目标:学习在 JSP 文件中使用各种声明语句的方法。
案例知识要点:JSP 中借助于声明定义类的属性、方法和变量,变量和方法的使用。
案例完成步骤:
1.新建一个 web 项目,在 WebRoot 中新建下面的 JSP 页面。
2.编写使用 JSP 声明的 JSP 文件 declarationdemo.jsp。
【程序代码】declarationdemo.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<html>
<%!int i=0;%>
<%!String strTmp="";%>
<html>
<head>
<title>Declaration Demo</title>
</head>
<body>
<%
i=13;
strTmp="Declaration Demo!";
out.print("The Value of i is:");
out.print(i);
out.print("<br>");
out.print(strTmp);
%>
</body>
</html>
【程序说明】
第 2 行:声明整型变量 i;
第 3 行:声明字符型变量 strTemp;
第 10 行:整型变量 i 赋值为 10;
第 11 行:字符型变量 strTemp 赋值为“Declaration Demo!”;
第 12 行—第 13 行:输出 i 值;
评论0
最新资源