JSP中的注释风格和方式

JSP中使用四种注释的方式:

1 <%-- comments --%>
2 // comments
3 /** comments **/
4 <!-- comments -->

 

JSP本身包括两种不同的注释:

一种是<!-- comments -->,这种HTML风格的注释完全被JSP引擎和浏览器忽视,不做任何处理。本质上是被当作template data,可以在客户端通过浏览器的查看源代码显示。使用这种注释的目的是为了良好的编码风格,增强可读性。

 

另外一种是<%-- comments --%>,这种注释的内容会被JSP引擎解析处理,并且在生成新的页面前被"毁尸灭迹"。本质上是被当作element data,不可以在客户端被显示。通常使用这种注释是不想在客户端暴露实现的逻辑,增强安全性。

 

// comments 和 /** comments **/ 是java编码风格的注释,用于脚本元素中。例如:

 

<%

    // 得到系统当前的calendar

    java.util.Calendar currentCal = java.util.Calendar.getInstance();


     /**
          计算年月日,生成日历表

          **/

 

// Set the current day of the month
int currentDay =
currentCal.get(currentCal.DAY_OF_MONTH);
// Calculate the totals days in the month
int daysInMonth =
currentCal.getActualMaximum(currentCal.DAY_OF_MONTH);
// Calculate the day of the week for the first
currentCal.set(currentCal.DAY_OF_MONTH, 1);
int dayOfWeek = currentCal.get(currentCal.DAY_OF_WEEK);
// Prefill the calendar with blank spaces
if (dayOfWeek != 1) {
out.println(" <TD COLSPAN=" + (dayOfWeek-1) +
">&nbsp;</TD>");
}
// Fill in dates
for (int day=1; day <= daysInMonth; day++) {
if (day == currentDay) {
out.println(" <TD CLASS='currentDay'>" + day +
"</TD>");
} else {
out.println(" <TD CLASS='otherDay'>" + day +
"</TD>");
}
if (dayOfWeek == 7) {
out.println(" </TR>/n/n <TR>");
dayOfWeek = 1;
} else {
dayOfWeek++;
}
}
// Postfill the calendar with blank spaces
if ((8-dayOfWeek) != 0) {
out.println(" <TD COLSPAN=" + (8-dayOfWeek) +
">&nbsp;</TD>");
}

%>      

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值