十月四日JSP作业

 GetArea.tag文件

<%@tag pageEncoding="UTF-8"
%>
<%@attribute name="sideA" required="true" %>
<%@attribute name="sideB" required="true"
%>
<%@attribute name="sideC" required="true" %>
<%@variable name-given="one" variable-class="java.lang.Double" scope="AT_BEGIN" %>
<%@variable name-given="two" variable-class="java.lang.Double" scope="AT_BEGIN" %>

<%--定义方法--%>
<%! public double triangleArea(String sideA,String sideB,String sideC){

    double a=Double.parseDouble(sideA);
    double b=Double.parseDouble(sideB);
    double c=Double.parseDouble(sideC);
    if((a+b)>c&&(a+c)>b&&(b+c)>a){
        double p=(a+b+c)/2.0;
        double area=Math.sqrt(p*(p-a)*(p-b)*(p-c));
        return area;
    }else {
        return -1.0;
    }
}
%>

<%
    jspContext.setAttribute("one",triangleArea(sideA,sideB,sideC));
    jspContext.setAttribute("two",triangleArea(sideA,sideB,sideC));
%>

one.jsp文件

<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/10/9
  Time: 15:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib tagdir="/WEB-INF/tags/tree_7" prefix="getArea" %>
<html>
<head>
    <title>Title</title>
</head>
<body bgcolor="orange">
    <getArea:GetArea sideA="5" sideB="7" sideC="8"></getArea:GetArea>
    <p style="font-size: 30px; font-family: 宋体; color: red">
        三条边分别为5,7,8三角形的面积(保留三位小数)是:
        <%=String.format("%.3f",one)%>
    </p>
</body>
</html>

 

two.jsp文件

<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/10/9
  Time: 16:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib tagdir="/WEB-INF/tags/tree_7" prefix="getArea" %>

<html>
<head>
    <title>Title</title>
</head>
<body>
<getArea:GetArea sideA="5" sideB="7" sideC="8"></getArea:GetArea>
<p style="font-size: 30px; font-family: 宋体; color: red">
    三角形的面积(保留6位小数)是:
    <%=String.format("%.6f",two)%>
</p>
</body>
</html>

注意路径

 

inputString.jsp文件

<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/10/11
  Time: 11:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body bgcolor="orange">

    <form action="computer.jsp" method="post" name="form">
        <p style="font-size: 40px;font-family: 楷体;color: red">
            输入字符串:<input type="text" name="string" >
            <br/>
            <input type="submit" name="submit" value="提交">
        </p>
    </form>

</body>
</html>

computer.jsp文件

<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/10/11
  Time: 11:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--定义方法--%>
<%!
    public int length(String str){
        int length = str.length();
        return length;
    }
%>
<html>
<head>
    <title>Title</title>
</head>
<body bgcolor="orange">

<%
    request.setCharacterEncoding("utf-8");
    String str = request.getParameter("string");
%>

<p style="font-size: 30px;font-family: 楷体;color: red">
    字符串<%=str%>的长度是<%=length(str)%>
</p>

</body>
</html>

 

 

 

 

<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/10/9
  Time: 18:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <p style="font-family: 宋体;font-size: 30px; color: blue">
    <form action="selectMusic.jsp" method="post" name="form">
        <select name="music">
            <option value="see_you_again.mp3">《See you again》</option>
            <option value="here_with_you.mp3">《Here with you》</option>
            <option value="fall_In_Love.mp3">《fall in love》</option>
            <option value="try.mp3">《Try》</option>
        </select>

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

    <%
        request.setCharacterEncoding("utf-8");
        String music = request.getParameter("music");
    %>
    <embed src="./music/<%=music%>"> 音乐<embed/>
</body>
</html>

注意路径

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

是语呀-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值