声明(类似于在java类中定义字段)
<%! int age=23;%>
小脚本(不能定义方法, 应为最终放在服务里面)
<%
int result=add(5,12);
%>
表达式
result:<%=result %>
body
<%@ page language="java" contentType="text/html; charset=UTF-8"
%>
<%!
int count =5;
int add(int a,int b){
return a+b;
}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
int result=add(5,12);
%>
count:<%=count %>
<br>
result:<%=result %>
<br>
for<%
for(int i=0;i<count;i++){%>
<br>i:<%=i %>
<% }%>
</body>
</html>
网友评论