Two methods
Two methods are available for JSP include files:
1. Use the include tag, such
<% @ Include file = "include. jsp" %>
2. Use the JSP: Include tag, such
<JSP: Include page = "include. jsp" Flush = "true">
<JSP: Param name = "Age" value = "32"/>
</Jsp: Include>
The difference is:
Method 1 is suitable for introducing static content with few changes, such as the header and footer parts of the webpage.
Method 2 is suitable for introducing pages with many changes.
Two JSP instances: Main. jsp and include. jsp
The content of include. jsp is the same:
<!-- include.jsp by oscar999--><%@ page contentType="text/html;charset=UTF-8" %><%@ page language="java" import="java.util.*" %> ===begin include jsp=== <p>Include JSP: </p> <p>CurDate <%=new Date()%></p> <% String str = request.getParameter("age");%>age:<%=str%> <br>===end include jsp===
The main. jsp import methods are different:
Method 1:
<!-- main.jsp by oscar999--><%@ page contentType="text/html;charset=UTF-8" %>
Method 2:
<!-- main.jsp by oscar999--><%@ page contentType="text/html;charset=UTF-8" %>Differences
The essence of JSP execution is that the web server will eventually convert it into a servlet for execution.
The. Java file converted by Tomcat is located in the relevant directory of work/Catalina/local.
Compare the differences between the two:
Java include section after method 1 is generated:
out.write("===begin include jsp=== \r\n"); out.write("<p>Include JSP: </p> \r\n"); String str = request.getParameter("age"); out.write("\r\n"); out.write("age:\r\n"); out.print(str); out.write(" <br>\r\n"); out.write("\r\n"); out.write("===end include jsp=== ");
Method 2 is as follows:
org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, "include.jsp" + (("include.jsp").indexOf('?')>0? '&': '?') + org.apache.jasper.runtime.JspRuntimeLibrary.URLEncode("age", request.getCharacterEncoding())+ "=" + org.apache.jasper.runtime.JspRuntimeLibrary.URLEncode("32", request.getCharacterEncoding()), out, true);
We can see that method 1 is a direct output, and method 2 is to be explained.
Supplement
During development, an easily differentiated suffix name may be given to the included JSP, such as. incjsp;
If method 2 is used for import, chrome and Firefox may cause problems. Will output the source code file of include. incjsp, instead of the generated HTML