<jsp:include page = ... > 和有什么不一样?和 <%@ 包含文件 = ... >? [英] What is the difference between <jsp:include page = ... > and <%@ include file = ... >?

查看:16
本文介绍了<jsp:include page = ... > 和有什么不一样?和 <%@ 包含文件 = ... >?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两个标签都包含另一个页面中的内容.

Both tags include the content from one page in another.

那么这两个标签之间的确切区别是什么?

So what is the exact difference between these two tags?

推荐答案

在一段可重用的代码中,我使用了 指令 <%@include file="reuse.html"%> 和在第二个我使用标准操作 .

In one reusable piece of code I use the directive <%@include file="reuse.html"%> and in the second I use the standard action <jsp:include page="reuse.html" />.

让可重用文件中的代码为:

Let the code in the reusable file be:

<html>
<head>
    <title>reusable</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
    <img src="candle.gif" height="100" width="50"/> <br />
    <p><b>As the candle burns,so do I</b></p>
</body>

运行这两个 JSP 文件后,您会看到相同的输出,并考虑 指令动作标记 之间是否有任何区别.但是,如果您查看两个 JSP 文件生成的 servlet,您就会发现不同之处.

After running both the JSP files you see the same output and think if there was any difference between the directive and the action tag. But if you look at the generated servlet of the two JSP files, you will see the difference.

当您使用指令时,您将看到以下内容:

Here is what you will see when you use the directive:

out.write("<html>
");
out.write("    <head>
");
out.write("        <title>reusable</title>
");
out.write("        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
");
out.write("    </head>
");
out.write("    <body>
");
out.write("        <img src="candle.gif" height="100" width="50"/> <br />
");
out.write("        <p><b>As the candle burns,so do I</b></p>
");
out.write("    </body>
");
out.write("</html>
");
 

这就是您将在第二个 JSP 文件中看到的用于标准操作的内容:

And this is what you will see for the used standard action in the second JSP file :

org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, "reusable.html", out, false);

所以现在您知道 include 指令 插入 reuse.html 在翻译时的源代码,但是 action 标记 插入 reuse.html 在运行时的响应.

So now you know that the include directive inserts the source of reuse.html at translation time, but the action tag inserts the response of reuse.html at runtime.

仔细想想,每个动作标签(<jsp:include>)都会带来额外的性能损失.这意味着您可以保证始终拥有最新的内容,但会增加性能成本.

If you think about it, there is an extra performance hit with every action tag (<jsp:include>). It means you can guarantee you will always have the latest content, but it increases performance cost.

这篇关于&lt;jsp:include page = ... &gt; 和有什么不一样?和 &lt;%@ 包含文件 = ... &gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆