jsp页面包含的几中方式

1)include指令

      include指令告诉容器:复制被包含文件汇总的所有内容,再把它粘贴到这个文件中。

<%@ include file="Header.jsp"%>

(2)include标准动作

(3)采用JSTL

和<%@include%>的区别
<%@include%>和的区别,发现了一些东西的。

<%@include%>:页面请求之前预编译,所有代码包含进来之后,一起进行处理,把所有代码合在一起,编译成一个servlet

:所有代码分别处理,在页面被请求的时候才编译,被编译成多个servlet,页面语法相对独立,处理完成之后再将代码的显示结果(处理结果)组合进来。

JSP中的两种包含页面的方法

第一种:include指令:当JSP转换成Servlet时引入指定文件

<%@ pagecontentType="text/html;charset=GB2312" language="java"errorPage=""%>
<%@ include file="head.jsp"%>
<%@ include file="body.jsp"%>
<%@ include file="tail.jsp"%>
第二种:<jsp:include>动作元素:当JSP页面被请求时引入指定文件
<%@ page contentType="text/html; charset=GB2312"language="java" errorPage=""%>
<jsp:include page="head.jsp"/>
<jsp:include page="body.jsp"/>
<jsp:include page="tail.jsp"/>
第二种方法可以很方便的用<jsp:param>来向所包含页传递参数,方法如下:
<%@ page contentType="text/html; charset=GB2312"language="java" errorPage=""%>
<jsp:include page="head.jsp"/>
<jsp:includepage="body.jsp">
<jsp:param name="uid"value="username"/>
<jsp:param name="pwd"value="password"/>
</jsp:include>
<jsp:includepage="tail.jsp"/>

 

:动态包含

第一种情况(包含的是html文件):

DynamicInclude.jsp:

复制代码
<%@pagecontentType="text/html;charset=gb2312"%>


动态包含

<bodystyle=" margin: 0px; padding: 0px; color: rgb(0, 0, 255);">>
               <jsp:include page="header.html"flush="true"/><!--动态包含-->

               <tableborder="1" align="center">
                        <tr>
                                 <td>姓名</td><td>性别</td><td>年龄</td><td>爱好</td>
                        </tr>
                        <tr>
                                 <td>a</td><td>b</td><td>c</td><td>d</td>
                        </tr>
               </table>
     </body>

复制代码
```

Header.html :

<h2style="font-family:arial;color:red;font-size:25px;text-align:center">
动态包含的标题(HTML)

运行之后,只生成一个servlet,和上面的代码对应如下:

复制代码
out.write("\r\n");
out.write("\r\n");
out.write("\t

\r\n");
out.write("\t\t动态包含\r\n");
out.write("\t\r\n");
out.write("\t<bodystyle="background-color:lightblue">\r\n");
out.write("\r\n");
out.write("\t\t");
org.apache.jasper.runtime.JspRuntimeLibrary.include(request,response, "header.html", out, true);
out.write("\r\n");
out.write("\r\n");
out.write("\t\t
姓名性别年龄爱好
abcd
\r\n");
out.write("\t\r\n");
out.write("

转载于:https://www.cnblogs.com/userzf/p/9407045.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值