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>
注意路径