主页面t2.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
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=utf-8">
<title>include动作--不带参数</title>
</head>
<body>
<div style="text-align:center">
<h1>请输入一个正数,单击按钮求这个数的平方根。</h1>
<hr>
<jsp:include page="t2_ok.jsp" />
</div>
</body>
</html>
辅页面t2_ok.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
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=utf-8">
<title>Insert title here</title>
</head>
<body>
<%
double num = 0;
String str=request.getParameter("num");
try{
if(str!=null){
num = Double.parseDouble(str);
}else{
out.println("【提示:】请输入数据,谢谢!");
}
} catch(Exception e){
out.println("只能输入数字") ;
}
%>
<p>请输入一个数字,谢谢!</p>
<form action="#" method="post" name="form">
<input type="text" name="num"><br><br>
<input type="submit" name="submit" value="开始计算">
</form>
<p><%=num%>的平方根是:<%=Math.sqrt(num)%></p>
</body>
</html>