java - JSP 中的 include 工作方式与 PHP 中的 include 类似吗?

标签 java php jsp servlets include

JSP 中的 include 工作方式与 PHP 中类似吗?我的意思是在执行之前只是静态复制粘贴?

<jsp:include page="header.jsp" /> 
//vs.
<?php include("header.jsp"); ?>


我唯一担心的是我有例如 Index.java = servlet 它将某些内容重定向或转发到index.jsp,在index.jsp上我称之为:

<c:if test="${sessionScope.user != null }"> //etc.


如果我将这部分代码移至 header.jsp,这将是每个页面上的代码的相同部分,如果它只是将 header.jsp 中的几行硬复制到我在执行之前将其包含在内的 index.jsp .

如果我以不同的方式写它,如果这两个选项相同:
在将 header 移出到单独的文件之前:
索引.jsp:

<!-- some code here -->
<!--header code -->
<!-- rest of code index.jps -->

将标题移出到单独的文件后:
header.jsp:

<!--header code -->

index.jsp:

<!-- some code here -->
<!-- header isn't here it was moved to header.jsp and I include that file
     where I can easily change for every page at one place -->
<jsp:include page="header.jsp" /> 
<!-- rest of code index.jps -->


为了总结我的问题,我想知道我对包含在 JSP 中的行为的期望是否可以,这意味着这两个示例是否工作完全相同。 (“假设文件存在并且可以访问”)。

最佳答案

在实现上存在一些差异,但在行为上答案是。 您可以阅读更多相关信息here .

关于java - JSP 中的 include 工作方式与 PHP 中的 include 类似吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21208493/

相关文章:

java - 如何编写一个将字符串作为参数并返回该字符串的递归方法?

java - 如何在 Swing 应用程序中获得类似 Intellij Idea 的外观和感觉?

php - Yii:自定义 CRUD/管理 URL

java - JSP - 帮助在分页中生成固定数量的链接

java - Google App Engine - Blobstore 请求用于生产而不是开发

java - JSP EL 中的三元运算符失败

java - 在 Class.forName 在 j2me 中混淆时得到 ClassNotFoundException

java - Jersey Response.ok() 没有给出 200 OK

php - 在 PHP 中使用 UPDATE 命令的问题

PHP/Laravel - 有条件地显示 Blade View