jsp:include 通过变量作为路径动态引入
语法:<jsp:include page="<%=整体是个变量%>" flush="true"/>
示例:
<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <% // 用来确定是加载page1.jsp还是用来加载page2.jsp; { // ...... } // 假设确定的结果是加载page2.jsp String loadPageUrl = "/jsp/page2.jsp"; %> </head> <body> <div> 这里是主页的内容:coding...... </div> <!-- 动态的选择加载哪个jsp来构建页面; --> <jsp:include page="<%=loadPageUrl%>" flush="true"></jsp:include> </body> </html>