jsp學習之scriptlet的使用方法詳解
更新時間:2020年07月23日 11:01:02 作者:Hackerman
這篇文章主要介紹了jsp學習之scriptlet的使用方法詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
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學習之scriptlet的使用方法詳解的文章就介紹到這了,更多相關(guān)jsp scriptlet 內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
詳解struts2的token機制和cookie來防止表單重復提交
這篇文章主要介紹了詳解struts2的token機制和cookie來防止表單重復提交的相關(guān)資料,需要的朋友可以參考下2017-06-06

