jsp指令
The include directive tells the Web Container to copy everything in the included file and paste it into current JSP file. Syntax of include directive is:
include指令告诉Web容器复制包含文件中的所有内容并将其粘贴到当前JSP文件中。 include指令的语法为:
<%@ include file="filename.jsp" %>
包含指令的示例 (Example of include directive)
welcome.jsp
welcome.jsp
<html>
<head>
<title>Welcome Page</title>
</head>
<body>
Welcome, User
</body>
</html>
header.jsp
header.jsp
<html>
<body>
<img src="header.jpg" alt="This is Header image" / >
</body>
</html>
The example above is showcasing a very standard practice. Whenever we are building a web application, with webpages, all of which have the top navbar and bottom footer same. We make them as separate jsp files and include them using the include
directive in all the pages. Hence whenever we have to update something in the top navbar or footer, we just have to do it at one place. Handy, isn't it?
上面的示例展示了非常标准的做法。 每当我们构建带有网页的Web应用程序时,它们的顶部导航栏和底部页脚都相同。 我们将它们制作为单独的jsp文件,并在所有页面中使用include
指令将它们include
。 因此,每当我们必须更新顶部导航栏或页脚中的某些内容时,我们只需要在一个地方进行即可。 方便,不是吗?
One more standard application of include
directive is, if you create a separate jsp file, with some commonly used functions, kind of like a util jsp file. Which can be included in the web pages wherever you want to use those functions.
include
指令的另一个标准应用程序是,如果您创建一个单独的具有某些常用功能的jsp文件,则类似于util jsp文件。 无论您想在何处使用这些功能,都可以将其包含在网页中。
Similarly, there are many ways in which this directive proves to be quite useful in giving a structure to your web application code.
同样,在很多情况下,此伪指令在为Web应用程序代码提供结构时也非常有用。
翻译自: https://www.studytonight.com/jsp/jsp-include-directive.php
jsp指令