开发者

JSP equivalent to the PHP include() function?

开发者 https://www.devze.com 2022-12-16 18:29 出处:网络
How should I include an HTML file into an开发者_JS百科other HTML file, using JSP? <jsp:include page="/include.html"></jsp:include>

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号