JSP脚本

2020-03-11  本文已影响0人  开心的小哈

声明(类似于在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>
上一篇 下一篇

猜你喜欢

热点阅读