JSP include file Method

Source: Internet
Author: User
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

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.