实验7 内置对象response

编写代码,掌握request、response的用法。【参考课本4.6.2】

三、源代码以及执行结果截图:

input.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"

  pageEncoding="utf-8"%>

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>Insert title here</title>

</head>

<body bgcolor=#ffccff>

  <form action="computer.jsp" method=post name=form>

     <p style="font-family:宋体;font-size:18; color:blue">

       输人运算数,选择运算符号:<br>

       <input type=text name="numberOne" size=6/>

         <select name="operator">

            <option selected="selected" value="+">

            <option value="-">

            <option value="*">

            <option value="/">

         </select >

<input type = text name = "numberTwo"size=6/>

<br><input type="submit" name="submit"  value="提交"/>

</form>

</p>

</body>

</html>

comput.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"

  pageEncoding="utf-8"%>

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>Insert title here</title>

</head>

<body bgcolor=cyan>

  <p style="font-family: 宋体;font-size: 18;color: black;">

     <%

       String numberOne = request.getParameter("numberOne");

       String numberTwo = request.getParameter("numberTwo");

       String opertor = request.getParameter("operator");

       if(numberOne == null || numberOne.length() == 0){

         response.sendRedirect("input.jsp");

         return;

       }

       else if(numberTwo == null || numberTwo.length() == 0){

         response.sendRedirect("input.jsp");

         return;

       }

       try{

         double a = Double.parseDouble(numberOne);

         double b = Double.parseDouble(numberTwo);

         double r = 0;

         if(opertor.equals("+"))

            r = a + b;

         else if(opertor.equals("-"))

            r = a - b;

         else if(opertor.equals("*"))

            r = a * b;

         else if(opertor.equals("/"))

            r = a / b;

         out.print(a + "" + opertor + "" + b + "=" + r);

       }

       catch(Exception e){

         out.print("请输入数字字符");

       }

     %>

  </p>

</body>

</html>

效果图

相关推荐

  1. js有哪些对象

    2024-03-29 06:06:04       48 阅读
  2. 【MySQL】7.MySQL 的函数

    2024-03-29 06:06:04       25 阅读
  3. Response对象的学习

    2024-03-29 06:06:04       30 阅读
  4. Request对象Response对象

    2024-03-29 06:06:04       55 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-29 06:06:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-29 06:06:04       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-29 06:06:04       82 阅读
  4. Python语言-面向对象

    2024-03-29 06:06:04       91 阅读

热门阅读

  1. Kafka硬核干货

    2024-03-29 06:06:04       40 阅读
  2. 【React】React AJAX

    2024-03-29 06:06:04       41 阅读
  3. Hive详解(1)

    2024-03-29 06:06:04       39 阅读
  4. 利用scala书写spark程序实现wordCount

    2024-03-29 06:06:04       48 阅读
  5. Rabbitmq消息重复消费

    2024-03-29 06:06:04       44 阅读
  6. OpenCV图像二值化

    2024-03-29 06:06:04       36 阅读