Description of the problem
When the page is set up, there is such a demand, want to refer to the local page of another dynamic jsp. Jsp path here "dynamic" means a reference variable. For example, we hope that the page may be partial or page1.jsp page2.jsp.
2 Solutions
2.1 Solution Description
I am using imported technology to achieve dynamic jsp. Dynamic code introduced as follows. Focus of this paper is to discuss 文件的url
, you can be variable?<jsp:include page="文件的url" flush="true"/>
The answer is yes, but 文件的url
this is a whole variable job, I tried <%=变量%>
as 文件的url
part of the discovery is not feasible. The following wording is feasible.<jsp:include page="<%=整体是个变量%>" flush="true"/>
2.2 Examples
For example described above conclusions.
Examples: target: page2.jsp dynamic reference page1.jsp or constructed in the home.jsp home.jsp. Again gives a simple demo.
Used files directory structure:
home.jsp code:
<%@ 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>
这里是主页的内容:^V^, enjoy coding......<br/><br/>
</div>
<!--
动态的选择加载哪个jsp来构建本页面;
-->
<jsp:include page="<%=loadPageUrl%>" flush="true"></jsp:include>
</body>
</html>
page1.jsp code:
<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<div>
这里page1.jsp的内容;
</div>
page2.jsp code:
<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<div>
这里page2.jsp的内容;
</div>
Implementation of the results:
We can <% %>
code segments which, together with our business logic, to determine which path url loaded.
2.3 js infeasible to modify the path described ideas
I thought of using js to dynamically modify jsp:include
the introduction path. The idea is not feasible.
The reason: This is a loaded question jsp timing. jsp:include
The contents executed first. js script loading and execution order of the html content in the jsp:include
execution after the execution.
Obviously, this idea is not feasible.
Reference 3
HTTPS: //blog.csdn.net/user_lo ... (JSP import static and dynamic import)
HTTPS: //bbs.csdn.net/topics/6 ... (JSP: Can contain the include variables?)
HTTPS: / ... /blog.csdn.net/qq_2103 (JSP nature, jsp dynamic and static import to import the difference, jsp nine built-in objects, jsp by value)
HTTPS: //www.cnblogs.com/alter ... (JSP page in <!%%> and <%> and <% =%>)
HTTPS: //blog.csdn.net/wzy_346 ... loading order (jsp pages code execution)