语法 | 描述 |
---|---|
jsp:include |
用于在当前页面中包含静态或动态资源 |
jsp:forward |
从一个JSP文件向另一个文件传递一个包含用户请求的request对象 |
index.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Insert title here</title> </head> <body> <% String side = request.getParameter("side"); if(side == null) { %> <jsp:forward page="index.jsp"> <jsp:param name="side" value="10"/> </jsp:forward> <% } int l = Integer.parseInt(side); %> <h3>实验三:计算立方</h3> <jsp:include page="page1.jsp"> <jsp:param name="side" value="<%=l %>" /> </jsp:include> </body> </html>
page1.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Insert title here</title> </head> <body> <% String side = request.getParameter("side"); int l = Integer.parseInt(side); %> <%=side %>的立方是: <%= l*l*l %> </body> </html>