<!--
<%! %>:可以修饰全局变量、常量、类、方法
对应java类中的成员变量、常量、内部类、成员方法
-->
<%!
int num=10;//全局变量
public static final String s="hello";//全局常量 public int add(int ...args){//方法
int sum=0;
for(int x:args){
sum+=x;
}
return sum;
}
class Phone{//类
private String brand;
private Double price;
public Phone(String brand,Double price){
this.brand=brand;
this.price=price;
} public String toString(){
return "brand="+brand+",price="+price;
}
}
%>
<%
out.println(num++);
out.println(s);
Phone p=new Phone("xiaomi",123.0);
out.println(p.toString());
out.println(add(10,20,30));
%>
<!--
<% %>:可以修饰局部变量、编写代码
--> <%
//局部变量
int num=10;
//编写代码
if(num>10){
out.println("num first");
}else{
out.println("num second");
}
%>
<!--

    测试代码:JSP-->Javascript

--->
<script type="text/javascript">
var arr=new Array();
<%
int[] data=new int[]{1,2,3,5};
for(int i=0;i<data.length;i++){
out.println(data[i]);//1,2,3,5
out.println("arr["+i+"]="+data[i]+";");//arr[0]=1;
}
%>
window.onload=function(){
var myDiv=document.getElementById("myDiv");
myDiv.innerHTML="LENGTH="+arr.length;
}
</script>
<div id="myDiv"></div>
 <%=%>:输出变量或者是常量(jsp代码与html、javascript代码分离)

<table>
<%
for(int i=0;i<10;i++){
%>
<tr>
<%
for(int j=0;j<10;j++){
%>
<td><%=i+j%></td>
<%
}
%>
</tr>
<%
}
%>
</table>
总结:
1."<%!%>":定义全局常量;
2."<%%>":局部变量、编写语句;
3."<%=%>":输出变量或者是常量;

scriptlet的更多相关文章

  1. 三种Scriptlet总结

    什么是Scriptlet? 在JSP中,Scriptlet称为脚本小程序,所欲嵌套在HTML代码中的Java程序都必须使用Scriptlet标记出来. 第一种:<% %> 在此Script ...

  2. [Java Web] 5、JSP (1) 注释 & Scriptlet

    >_<" 在JSP中支持两种注释的语法操作,一种是显式注释,这种注释客户端是允许看见的,另外一种是隐式注释,此种注释客户端是无法看见的. 显式注释语法: <!-- 注释内容 ...

  3. eclipse调试jsp中的scriptlet代码

    在eclipse开发环境下,jsp中的scriptlet代码,也就是<%%>中的java代码,跟普通的java代码一样可以打断点单步调试的! 做个笔记,免得自己忘了!

  4. JSP注释及scriptlet <%局部%><%!全局%><%=输出%>

    显示注释: <!--注释内容-->> 隐式注释: 1. // 2./* */ 3. <%-- 注释内容--%> <!-- 这个注释客户端就可以看见 --> & ...

  5. Applet、Scriptlet与Servlet

    Applet.Scriptlet与Servlet - 青春念邵的博客 - 博客频道 - CSDN.NEThttp://blog.csdn.net/mo_fan_qing_wa/article/deta ...

  6. 声明元素<%! %>、Scriptlet元素<% %>、表达式元素<%= %>、注释元素、输出特殊符号<%和%>

    声明元素 <%! 类成员声明或方法声明 %> 在声明元素中编写的代码,将转译为Servlet中的类成员或方法. 重新定义jspInit()方法,或是在jspDestroy(),就是在声明元 ...

  7. yum 卸载 error: %preun(tengine-2.1.0-1.el6.x86_64) scriptlet failed, exit status 6

    error: %preun(tengine-2.1.0-1.el6.x86_64) scriptlet failed, exit status 6 Error in PREUN scriptlet i ...

  8. CGI servlet Applet Scriptlet Scriptlet JSP data layer(数据层),business layer(业务层), presentation layer(表现层)

    https://en.wikipedia.org/wiki/Common_Gateway_Interface In computing, Common Gateway Interface (CGI) ...

  9. 利用script和scriptlet moniker绕过脚本白名单限制

    没事儿看了一下subtee和enigma0x3今年在BSides Nashville 2017上的演讲,觉得这两个猥琐男简直不能再猥琐了 :-)其中有一个猥琐小技巧,又可以让我们好好hunting一番 ...

  10. jsp学习之scriptlet的使用方法

    scriptlet的使用 jsp页面中分三种scriptlet: 第一种:<%  %>  可以在里面写java的代码.定义java变量以及书写java语句. 第二种:<%! %> ...

随机推荐

  1. ntp/系统时钟/硬件时钟/双系统下计算机时间读取的问题

    http://blog.chinaunix.net/uid-182041-id-3464524.html       //linux系统时间和硬件时钟问题(date和hwclock) http://j ...

  2. 【C语言学习笔记】字符串拼接的3种方法 .

    昨天晚上和@buptpatriot讨论函数返回指针(malloc生成的)的问题,提到字符串拼接,做个总结. #include<stdio.h> #include<stdlib.h&g ...

  3. JsRender 前端渲染模板常用API学习

    JsRender 常用API 1. $.templates() $.templates()方法是用来注册或编译模板的,使用的情况有以下几种. 把html字符串编译编译成模板 获取使用script标签声 ...

  4. 不同意义的new和delete

    补充说明: new/delete是运算符而非函数,operator new/delete并非是new/delete的重载.事实上,我们无法自定义new/delete的行为: operator new/ ...

  5. (三)HttpClient 抓取图片

    第一节: HttpClient 抓取图片 这里pom.xml需要用到io输入输出: <dependency> <groupId>commons-io</groupId&g ...

  6. python 删除前3天的文件

    一.需求分析 1. 删除前3天的文件 2.如果目录为空,也一并删除掉 如果使用shell脚本,一条命令就搞定了.干啥还要用python? 1. 因为需要记录一些日志,使用shell不好实现 2. 作为 ...

  7. R vs Python:载入包 import & library

    数据科学:R & Python 工作 & Kaggle机器学习比赛 可重复函数式编程 一.Python模块的载入 包 Package 模块 module import pandas a ...

  8. 微信小程序地图模块

    微信小程序的地图模块官方提供的API比较少,详情请见   官方文档 以下为一个示例                               <!--pages/location/locati ...

  9. Spring整合junit测试

    本节内容: Spring整合junit测试的意义 Spring整合junit测试 一.Spring与整合junit测试的意义 在没整合junit之前,我们在写测试方法时,需要在每个方法中手动创建容器, ...

  10. (使用通过混淆+自己第三方保留成功混淆)AndroidStudio 混淆打包

    原文:https://blog.csdn.net/mazhidong/article/details/64820838 AndroidStudio中的项目可以用compile的形式引入github上的 ...