当前位置:编程学习 > JS >>

jsp---简单的计算器

简单的计算器
 
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包

摘自 张大鹏的博客
补充:Web开发 , Jsp ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,