Jsp include

Source: Internet
Author: User
Tags flush

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 <%
   }
%>
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.