网络技术编程JSP求阶乘实验
时间: 2023-12-14 08:31:56 浏览: 75
以下是使用JSP编写求阶乘的实验代码:
```jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>阶乘实验</title>
</head>
<body>
<h1>阶乘实验</h1>
<form action="" method="post">
<label for="num">请输入一个正整数:</label>
<input type="number" name="num" id="num" required>
<br><br>
<input type="submit" value="计算">
</form>
<%
int num = Integer.parseInt(request.getParameter("num"));
long result = 1;
for (int i = 1; i <= num; i++) {
result *= i;
}
out.println(num + "的阶乘为:" + result);
%>
</body>
</html>
```
阅读全文