首页 > 代码库 > 静态包含——动态包含

静态包含——动态包含

include.jsp

<%@ page contentType="text/html" pageEncoding="utf-8"%><html>    <head><title>frfrfr</title></head>    <body>        <h1>静态包含</h1>        <h3><%@ include file = "info.html"%></h3>        <h3><%@ include file = "info.jsp"%></h3>        <h3><%@ include file = "info.inc"%></h3>    </body></html>

info.html

 <h2><font color = "red">info.html</font></h2>

info.ioc

 <h2><font color = "blue">info.inc</font></h2>

info.jsp

 <h2><font color = "blue">info.inc</font></h2>

静态包含直接替换。

 

 

动态包含:

der.jdp

<%@ page contentType="text/html" pageEncoding="utf-8"%><html>    <head><title>frfrfr</title></head>    <body>        <h1>动态包含</h1>        <jsp:include file = "info.html"/>        <jsp:include file = "info.jsp"/>        <jsp:include file = "info.inc"/>    </body></html>

demo.jsp

<%@ page contentType="text/html" pageEncoding="GBK"%><html><head><title>www.mldnjava.cn,MLDN高端Java培训</title></head><body>    <h1>动态包含操作</h1>    <%        String username = "lop" ;    %>    <jsp:include page="receive_param.jsp">        <jsp:param name="name" value="<%=username%>"/>        <jsp:param name="info" value="www.mldnjava.cn"/>    </jsp:include></body></html>
receive_param.jsp
<%@ page contentType="text/html" pageEncoding="GBK"%><h1>参数一:<%=request.getParameter("name")%></h1><h1>参数二:<%=request.getParameter("info")%></h1>

静态变量重复

demo4.jsp

<%@ page contentType="text/html" pageEncoding="GBK"%><html><head><title>yyy</title></head><body>    <%        int x = 100 ;    // 变量重复    %>    <h1>demo04.jsp -- <%=x%></h1>    <%@include file="include.jsp"%></body></html>

include.jsp

<%    int x = 10 ;%><h1>include.jsp -- <%=x%></h1>

这样会出错。

动态变量的重复:

<%@ page contentType="text/html" pageEncoding="GBK"%><html><head><title>www.mldnjava.cn,MLDN高端Java培训</title></head><body>    <%        int x = 100 ;    // 变量重复    %>    <h1>include_demo04.jsp -- <%=x%></h1>    <jsp:include page="include.jsp"/></body></html>

动态包含变量名重复是可以的。

 

标签必须完结

 

静态包含——动态包含