簡單的計算器
01
<%@page language="java" contentType="text/html;charset=gb2312"%>
02
<!DOCTYPE html>
03
<html>
04
<head>
05
<title>簡單計算器</title>
06
</head>
07
<body>
08
<h1>簡單計算器</h1>
09
<hr />
10
<form action="result.jsp">
11
<input type="text" name="number1"/>
12
<select name="ope">
13
<option value="add">+</option>
14
<option value="minus">-</option>
15
<option value="multiply">*</option>
16
<option value="div">/</option>
17
</select>
18
<input type="text" name="number2"/>
19
<input type="submit" value="計算" />
20
<input type="reset" value="重置">
21
</form>
22
</body>
23
</html>
01
<%@page language="java" contentType="text/html;charset=gb2312"%>
02
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
03
<!DOCTYPE html>
04
<html>
05
<head>
06
<title>簡單計算器</title>
07
</head>
08
<body>
09
<h1>簡單計算器</h1>
10
<hr />
11
<c:if test="${param.ope == 'add'}">
12
${param.number1} + ${param.number2} = ${param.number1 + param.number2}
13
</c:if>
14
<c:if test="${param.ope == 'minus'}">
15
${param.number1} - ${param.number2} = ${param.number1 - param.number2}
16
</c:if>
17
<c:if test="${param.ope == 'multiply'}">
18
${param.number1} * ${param.number2} = ${param.number1 * param.number2}
19
</c:if>
20
<c:if test="${param.ope == 'div'}">
21
${param.number1} / ${param.number2} = ${param.number1 / param.number2}
22
</c:if>
23
</body>
24
</html>
這裡有個小插曲,就是在WEB-INF文件夾下面,在lib的目錄中必須有jstl.jar和standard.jar這兩個jar包
摘自 張大鵬的博客