JSP equivalent to PHP include () function?

I just want to include the HTML file in another HTML file using JSP. PHP is not available. Is that what I want?

<jsp:include page="/include.html"></jsp:include> 
+7
include php jsp server-side-includes
source share
2 answers

You have several 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? First of all, <jsp:include> inserts the contents of another JSP page within the same JAR relative to the current page, while <c:import> can read the absolute or relative URL and display this content on the page, retrieve the Reader or save the contents in variable.

The syntax for both XML-like is:

 <jsp:include page="header.jsp"/> 

or

 <jsp:include page="header.jsp"></jsp:include> 

Note. both can take parameters.

+9
source share

For those who want to have the same behavior as PHP include () or <!--#include file="header.jsp"--> , with a common global scope in JSP, use the following command:

 <%@include file="header.jsp"%> 

Link: Here

+1
source share

All Articles