scriptlet的使用
- jsp页面中分三种scriptlet:
- 第一种:<% %> 可以在里面写java的代码。定义java变量以及书写java语句。
- 第二种:<%! %> 可以在里面定义全局变量以及方法,类。
- 第三种:<%=%> 用于打印变量或者输出值。
<% %>的使用
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21<html> <head> <title>this is java page</title> </head> <body> <!--显示注释 注释内容 --> <% int x=10; int y=20; String str=request.getParameter("info"); out.println("<h1>"+str+"</h1>"); out.println("<h1>"+(x+1)+"</h1>"); out.println("<h2>"+y+"</h2>"); %> </body> </html>
<%! %>的使用
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55<html> <head> <title>this is java page</title> </head> <body> <!--显示注释 注释内容 --> <%! public static final int x=10; %> <%! public int add(int x,int y) { return x+y; } %> <%! 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="+name+",age="+age; } } %> <%! public int li=20; %> <% person p=new person("test",10); out.println(p); out.println(li); out.println(add(x,20)); %> <% int b=10; out.println(b); %> </body> </html>
<%= %>的使用
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20<html> <head> <title>this is java page</title> </head> <body> <!--显示注释 注释内容 --> <% int x=10; int y=20; String str=request.getParameter("info"); %> <%=x%> <%=y%> <%="strinsssa"%> </body> </html>
到此这篇关于jsp学习之scriptlet的使用方法详解的文章就介绍到这了,更多相关jsp scriptlet 内容请搜索靠谱客以前的文章或继续浏览下面的相关文章希望大家以后多多支持靠谱客!
最后
以上就是清脆身影最近收集整理的关于jsp学习之scriptlet的使用方法详解的全部内容,更多相关jsp学习之scriptlet内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复