欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jsp---简单的计算器

程序员文章站 2022-06-23 16:26:10
简单的计算器   01 <%@page language="java" contenttype="text/html;charset=gb2312&qu...
简单的计算器
 
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.">
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="p">/</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="https://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 == 'p'}">
21
        ${param.number1} / ${param.number2} = ${param.number1 / param.number2}
22
        </c:if>
23
    </body>
24
</html>
这里有个小插曲,就是在web-inf文件夹下面,在lib的目录中必须有jstl.jar和standard.jar这两个jar包

摘自 张大鹏的博客