JSPDynamic inclusion<JSP: Include/>
Now let's take a look at the JSP dynamic include command: <JSP: Include/>
Create a project testinclude
Then add the file:
Index. jsp:
<%@ page language="java"import="java.util.*" pageEncoding="ISO-8859-1"%>
Curdate. Jsp:
<%@ page language="java"import="java.util.*" %><p>curDate.jsp: <%=new Date()%></p> <!-- curDate--><%= request.getParameter("user") %><p>curDate.jsp's request: <%out.println(request);%> </p>
View the result/source code:
View the Tomcat working directory:
View the index_jsp.java file:
try { response.setContentType("text/html;charset=ISO-8859-1"); pageContext =_jspxFactory.getPageContext(this, request,response, null, true, 8192, true); _jspx_page_context = pageContext; application =pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; out.write("\r\n"); out.write("
Curdate_jsp.java:
try { response.setContentType("text/html"); pageContext =_jspxFactory.getPageContext(this, request,response, null, true, 8192, true); _jspx_page_context = pageContext; application =pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; out.write("\r\n"); out.write("<p>curDate.jsp: "); out.print(new Date()); out.write("</p> <!-- curDate -->\r\n"); out.print( request.getParameter("user") ); out.write("\r\n"); out.write("<p>curDate.jsp's request: ");out.print(request); out.write(" </p>");} catch (java.lang.Throwable t) {
In the index_jsp.java File
<JSP: Include page ="Curdate. jsp? User = Ken"/> The statement is compiled into the following statement:
Org. Apache. Jasper. runtime. jspruntimelibrary. Include (request, response, "curdate. jsp? User = Ken ", out, false );
This dynamically changes the parameters (request, response, "curdate. jsp? User = Ken ", out, false); passed to curdate_jsp. java execution, note that these parameters are dynamic in the actual program, so when you execute this statement, curdate_jsp.class returns the result to index_jsp.class, the result is stored in the out object of the parameter .. simply put
Curdate. jsp gets the parameter and calculates the result, and then returns the result to index. jsp (dynamically called at runtime)