欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jsp學(xué)習(xí)之scriptlet的使用方法詳解

 更新時(shí)間:2020年07月23日 11:01:02   作者:Hackerman  
這篇文章主要介紹了jsp學(xué)習(xí)之scriptlet的使用方法詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

scriptlet的使用

  • jsp頁(yè)面中分三種scriptlet:
  • 第一種:<% %> 可以在里面寫java的代碼。定義java變量以及書寫java語(yǔ)句。
  • 第二種:<%! %> 可以在里面定義全局變量以及方法,類。
  • 第三種:<%=%> 用于打印變量或者輸出值。

<% %>的使用

<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)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論