< jsp:include page = ...>之间有什么区别?和<%@ include file = ...>? [英] What is the difference between <jsp:include page = ... > and <%@ include file = ... >?

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

问题描述

这两个标签都包含来自另一个页面的内容。

Both tags include the content from one page in another.

那么这两个标签之间的确切差异是什么?

So what is the exact difference between these two tags?

推荐答案

在一段可重复使用的代码中,我使用指令<%@ include file =reuse.html %> ,在第二个我使用标记 < jsp:include page =reuse.html/>

In one reusable piece of code I use the directive <%@include file="reuse.html"%> and in the second I use the tag <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 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>\r\n");
out.write("    <head>\r\n");
out.write("        <title>reusable</title>\r\n");
out.write("        <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\r\n");
out.write("    </head>\r\n");
out.write("    <body>\r\n");
out.write("        <img src=\"candle.gif\" height=\"100\" width=\"50\"/> <br />\r\n");
out.write("        <p><b>As the candle burns,so do I</b></p>\r\n");
out.write("    </body>\r\n");
out.write("</html>\r\n");

这是你将在第二个JSP文件中看到的二手标签:

and this is what you will see for the used tag in the second JSP file :

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

现在你知道include指令插入了的来源。 在翻译时,但是动作标签会在运行时插入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:包含文件)。这意味着您可以保证始终拥有最新内容,但会增加性能成本。

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

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

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