Dynamic JSP inclusion

Source: Internet
Author: User

JSPDynamic inclusion<JSP: Include/>

 

Now let's take a look at the JSP dynamic include command: <JSP: Include/>

 

Create a project testinclude

Then add the file:

 

Index. jsp:

 

<%@ page language="java"import="java.util.*" pageEncoding="ISO-8859-1"%>

 

Curdate. Jsp:

<%@ page language="java"import="java.util.*" %><p>curDate.jsp: <%=new Date()%></p> <!-- curDate--><%= request.getParameter("user") %><p>curDate.jsp's request: <%out.println(request);%> </p>

 

View the result/source code:

 

 

 

View the Tomcat working directory:

 

 

 

View the index_jsp.java file:

try {      response.setContentType("text/html;charset=ISO-8859-1");      pageContext =_jspxFactory.getPageContext(this, request,response,                null, true, 8192, true);      _jspx_page_context = pageContext;      application =pageContext.getServletContext();      config = pageContext.getServletConfig();      session = pageContext.getSession();      out = pageContext.getOut();      _jspx_out = out;      out.write("\r\n");      out.write("

Curdate_jsp.java:

try {      response.setContentType("text/html");      pageContext =_jspxFactory.getPageContext(this, request,response,                null, true, 8192, true);      _jspx_page_context = pageContext;      application =pageContext.getServletContext();      config = pageContext.getServletConfig();      session = pageContext.getSession();      out = pageContext.getOut();      _jspx_out = out;       out.write("\r\n");      out.write("<p>curDate.jsp: ");      out.print(new Date());      out.write("</p> <!-- curDate -->\r\n");      out.print( request.getParameter("user") );      out.write("\r\n");      out.write("<p>curDate.jsp's request: ");out.print(request);      out.write(" </p>");} catch (java.lang.Throwable t) {

 

In the index_jsp.java File

<JSP: Include page ="Curdate. jsp? User = Ken"/> The statement is compiled into the following statement:

 

Org. Apache. Jasper. runtime. jspruntimelibrary. Include (request, response, "curdate. jsp? User = Ken ", out, false );

 

This dynamically changes the parameters (request, response, "curdate. jsp? User = Ken ", out, false); passed to curdate_jsp. java execution, note that these parameters are dynamic in the actual program, so when you execute this statement, curdate_jsp.class returns the result to index_jsp.class, the result is stored in the out object of the parameter .. simply put

Curdate. jsp gets the parameter and calculates the result, and then returns the result to index. jsp (dynamically called at runtime)

 

 

 

 

 

 

 

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.