文章詳情頁
jsp學(xué)習(xí)之scriptlet的使用方法詳解
瀏覽:208日期:2022-06-08 09:53:04
scriptlet的使用
- jsp頁面中分三種scriptlet:
- 第一種:<% %> 可以在里面寫java的代碼。定義java變量以及書寫java語句。
- 第二種:<%! %> 可以在里面定義全局變量以及方法,類。
- 第三種:<%=%> 用于打印變量或者輸出值。
<% %>的使用
<html> <head> <title>this is java page</title> </head> <body> <!--顯示注釋 注釋內(nèi)容 --> <% 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>
<%! %>的使用
<html> <head> <title>this is java page</title> </head> <body> <!--顯示注釋 注釋內(nèi)容 --> <%! 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>
<%= %>的使用
<html> <head> <title>this is java page</title> </head> <body> <!--顯示注釋 注釋內(nèi)容 --> <% int x=10; int y=20; String str=request.getParameter("info"); %> <%=x%> <%=y%> <%="strinsssa"%> </body> </html>
到此這篇關(guān)于jsp學(xué)習(xí)之scriptlet的使用方法詳解的文章就介紹到這了,更多相關(guān)jsp scriptlet 內(nèi)容請搜索以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持!
標(biāo)簽:
JSP
相關(guān)文章:
排行榜
