I have a JSP file and in that file I am including another JSP file:
<c:forEach var="instanceVar" items="${instanceList}"> <c:set var="instance"><jsp:include page="instance.jsp"/></c:set> ... </c:forEach
In the file instance.jsp I want to use a variable instanceVar
. I want to do it using JSTL. Is there any way to do this?
To pass the parameters from index to file page we are using <jsp:param> action tag. We are passing three parameters firstname, middlename and lastname, for each of these parameters we need to specify the corresponding parameter name and parameter value.
To include JSP in another JSP file, we will use <jsp:include /> tag. It has a attribute page which contains name of the JSP file.
The jsp:include action tag is used to include the content of another resource it may be jsp, html or servlet. The jsp include action tag includes the resource at request time so it is better for dynamic pages because there might be changes in future.
<c:forEach var="instanceVar" items="${instanceList}"> <jsp:include page="instance.jsp"> <jsp:param name="myVar" value="${instanceVar}"/> </jsp:include> </c:forEach>
In the instance.jsp
<c:out value="${param.myVar}"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With