gpt4 book ai didi

java - 和 <%@ include file = ...> 有什么区别?

转载 作者:IT老高 更新时间:2023-10-28 11:24:19 26 4
gpt4 key购买 nike

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

那么这两个标签之间的究竟有什么区别

最佳答案

在一段可重复使用的代码中,我使用了 directive <%@include file="reuse.html"%>在第二个中,我使用 standard action <jsp:include page="reuse.html" /> .

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

<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 文件后,您会看到相同的输出,并考虑 directiveaction 标记 之间是否有任何区别。但是如果你查看生成的 servlet在这两个 JSP 文件中,您会看到不同之处。

以下是您在使用指令时会看到的内容:

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 文件中看到使用的标准 Action :

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

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

如果您考虑一下,每个 Action 标签 (<jsp:include>) 都会对性能产生额外影响。这意味着您可以保证始终拥有最新的内容,但会增加性能成本。

关于java - <jsp :include page = . ..> 和 <%@ include file = ...> 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7879906/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com