JSP equivalent to the PHP include() function?
How should I include an HTML file into an开发者_JS百科other HTML file, using JSP?
<jsp:include page="/include.html"></jsp:include>
You have a couple of options. The first is <jsp:include>
. The second is <c:import>
. The c:
tags are JSTL, the JavaServer Pages Standard Tag Library.
What's the difference? Primarily <jsp:include>
inserts the contents of another JSP page within the same JAR relative to the current page whereas <c:import>
can read in an absolute or relative URL and display those contents on the page, retrieve a Reader
or store the contents in a variable.
The syntax for both is XML-like so:
<jsp:include page="header.jsp"/>
or
<jsp:include page="header.jsp"></jsp:include>
Note: both can take parameters.
For those who want the same behavior as PHP include() or <!--#include file="header.jsp"-->
, with shared the global scope in JSP, use the following command:
<%@include file="header.jsp"%>
Reference: Here
精彩评论