一、结果图:
二、代码:
<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.util.Date" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>简单的JSP程序实例</title>
</head>
<body>
<%!int sum = 0, x = 1;%>
<%
while (x <= 10) {
sum += x;
++x;
}
%>
<h3>该程序的功能时计算1到10的累加结果,并显示时间!</h3>
<p>
1加到10 的结果是:<%=sum%></p>
<p>
程序的运行时间是:<%=new Date()%>
</body>
</html>