主页面t3.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>
<%
String num1= request.getParameter("num");
%>
<form action="#" method="post" name="form">
<input type="text" name="num" value="<%=num1 %>" ><br><br>
<input type="submit" name="submit" value="开始计算">
</form>
<hr>
<jsp:include page="t3_ok.jsp" >
<jsp:param name="num" value="<%=num1 %>" />
</jsp:include>
</div>
</body>
</html>
辅页面t3_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><%=num%>的平方根是:<%=Math.sqrt(num)%></p>
</body>
</html>