There are two types of include: <% @ Include file = "" %> and include action: <jsp tutorial: include page = "" flush = "true"/>
Include Call file
<% @ Include file = "" %>: integrates the introduced JSP with the original JSP, which is carried out in the translation phase.
Index. jsp
<% @ Page session = "false" %>
<H3> Flavors Our most popular flavors are:
<% @ Include file = "flavor_list.html" %>
Try them all!
Flavor_list.html
<Ol>
<Li> Chocolate </li>
<Li> Strawberry </li>
<Li> Vanilla </li>
</Ol>
When all parts of the page (such as the title, footer, and navigation bar) in the application are the same, we can consider using include. When <% @ include file = "" %> and <jsp: include page = "" flush = "true"/> are used. This form
Include the address of a page
<% @ Page session = "false" %>
<H3> Flavors Our most popular flavors are:
<Jsp: include page = "/" flush = "true"/>
Try them all!
Based on the parameter request submitted by the user, we call unnecessary files
Instance
<%
// Diameter of the earth in kilometers
Int distance = 12756;
%>
<% @ Page session = "false" %>
<H4> Diameter of the Earth in SI (Metric) Units <Jsp: include page = "ShowDiameter. jsp" flush = "true">
<Jsp: param name = "dist" value = "<% = distance %>"/>
<Jsp: param name = "units" value = "SI"/>
</Jsp: include>
<H4> Diameter of the Earth in U. S. Customary Units <Jsp: include page = "ShowDiameter. jsp" flush = "true">
<Jsp: param name = "dist" value = "<% = distance %>"/>
<Jsp: param name = "units" value = "US"/>
</Jsp: include>
ShowDiameter. jsp
<% @ Page session = "false" %>
<%
String dist = request. getParameter ("dist ");
If (dist = null)
Throw new ServletException
("No distance parameter specified ");
Int kilometers = Integer. parseInt (dist );
Double Mile = kilometers/1.609344;
String units = request. getParameter ("units ");
If (units = null)
Throw new ServletException
("No units parameter specified ");
If (units. equals ("SI ")){
%> Diameter = <% = kilometers %> km <%
}
Else {
%> Diameter = <% = miles %> miles <%
}
%>