JSP页面中<%! %>和<% %>有什么区别

 我来答
zhengmin200809
推荐于2018-05-02 · TA获得超过181个赞
知道答主
回答量:68
采纳率:0%
帮助的人:87万
展开全部
JSP声明语句:<%!声明语句%>,通常声明全局变量、常量、方法、类
JSP Scriptlet:<%java代码%>,其中可包含局部变量、java语句
JSP表达式:<%=java 代码%>
显示注释:即HTML注释,可以在客户端显示<!–注释部分-->
隐式注释:即JSP注释,不能在客户端显示<%--注释部分--%>

<!-- 显示注释:声明局部变量、java语句 -->
以下是举得例子,帮助你理解
<%
int result = 1;
out.println(NUM + "+" + result +" 结果 " + sum(NUM,result));
%>
<%-- 隐式注释:定义类、方法、全局变量、常量 --%>
<%!
private static final int NUM = 10 ; //常量
class Person{ // 类
private String name ;
private int age ;
public Person(String name , int age ) {
this.name = name ;
this.age = age ;
}
public String toString() {
return "name: " + this.name + "; age = " + this.age ;
}
}
public int sum(int num , int result) { // 方法
result+=num;
return result;
}
%>
<html>
<head>
<title>My JSP 'Jsp_01.jsp' starting page</title>
</head>
<body>
<center>
<h2 style="background-color: red">体会显示注释与隐式注释的区别</h2>
<p>第一步:鼠标右击 ;第二步:选择查看源文件;第三步:体会显示注释与隐式注释</p>
<h2 style="background-color: green"; align="center">JSP 脚本元素的使用</h2>
<P>两数字相加为:<%= sum(NUM,result)%></P>
</center>
</body>
</html>
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式