jsp include dynamic and static content contained achieve the same, but in different ways.
jsp static includes <file = ""%% @ include>
Creating include1.jsp and include2.jsp
include1.jsp Code
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ include file="include2.jsp"%> <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Insert title here</title> </head> <body> this is include page 1 </body> </html>
include2.jsp代
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Insert title here</title> </head> <body> this is include page 2 </body> </html>
operation result:
If it is still included, only generate a java file
The reason: Because include1.jsp should include2.jsp content exact quote, all include1.jsp will synthesize and include2.jsp a jsp, then translated into .java files, and finally compile and run.
jsp dynamic include <jsp: include page = ""> </ jsp: include>
Creating Newfile1.jsp and NewFile2.jsp
Newfile1.jsp Code
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Insert title here</title> </head> <body> <jsp:include page="/NewFile2.jsp"></jsp:include> this is newFile1 </body> </html>
Newfile2.jsp Code
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Insert title here</title> </head> <body> this is newFile2 </body> </html>
operation result:
If it contains a dynamic, two .java file is generated
The reason: because it is the first visit NewFile1.jsp, so first translated into NewFile1_jsp.java, and then found the code compile and run time , then return to visit NewFile2.jsp, then translated NewFile2_jsp.java, and finally compile the contents together.
Attach a FIG facilitate understanding:
Learn something every day, the importance of blogging, over time! ! !
If they find an error or big brother is not thorough, please leave a message pointed out! ! !