第七次作业

<%@ page language="java" contentType="text/html"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
   double price = 98.78;
%>
<p style="font-family:宋体;font-size:36;color:red">
商品编号A1001,价格8765
<a href ="Test.jsp?id=A1001&price=8765">购买</a><br>
商品编号A1002,价格<%= price%>
<a href ="Test.jsp?id=A1002&price=<%= price%>">购买</a>
</p>
</body>
</html>

 

 

<%@ page language="java" contentType="text/html"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta>
<title>Insert title here</title>
</head>
<body>
<p style="font-family:宋体;font-size:36;color:blue">
<%  String id = request.getParameter("id");
    String price = request.getParameter("price");
%>
<b>商品编号:<%= id %><br>
商品价格:<%= price %>
</p>
</body>
</html>

 

<%@ page language="java" contentType="text/html"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta >
<title>Insert title here</title>
</head>
<body>
<form action="work4.jsp" method=post name=form>
<p style="font-family:宋体;font-size:50;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="提交" size="10"/>
</p>
</form>
</body>
</html>

 

 

<%@ page language="java" contentType="text/html"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<p style="font-family:宋体;font-size:30;color:black">
<%
   String numberOne=request.getParameter("numberOne");
   String numberTwo=request.getParameter("numberTwo");
   String operator=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(operator.equals("+"))
           r=a+b;
        else if(operator.equals("-"))
           r=a-b;
        else if(operator.equals("*"))
           r=a*b;
        else if(operator.equals("/"))
           r=a/b;
        out.print(a+""+operator+""+b+"="+r);
    }
    catch(Exception e){
        out.println("请输入数字字符");
    }
%>
</body>
</html>

 

posted @ 2022-04-17 19:38  15*  阅读(7)  评论(0编辑  收藏  举报