Reputation: 3529
Does include in JSP works similarly like in PHP? I mean by this just static copy paste before an execution?
<jsp:include page="header.jsp" />
//vs.
<?php include("header.jsp"); ?>
Only thing I'm afraid of is that I have for example Index.java = servlet which redirect or forward something to index.jsp, on index.jsp I call something like:
<c:if test="${sessionScope.user != null }"> //etc.
If I move this part of code to the header.jsp which will be same part of code on every page, if it will just hard copy the few of lines which are in header.jsp to the index.jsp where I include it before execution.
If I write it different way if this two options are same:
Before moving the header out to separate file:
index.jsp:
<!-- some code here -->
<!--header code -->
<!-- rest of code index.jps -->
After moving the header out to separate file:
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 -->
To summarize my question I wanna know if my expectation of behavior of include in JSP is ok which mean if these two examples work exactly same. ("Suppose that the files exist and are accessible").
Upvotes: 2
Views: 1176
Reputation: 201409
There are some differences in implementation, but in the behavior the answer is yes. You can read more about it here.
Upvotes: 2