Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing parameters to another JSP file using <jsp:include> tag

Tags:

include

jsp

jstl

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?

like image 421
SIGSTP Avatar asked Oct 03 '13 04:10

SIGSTP


People also ask

How will you pass parameters in JSP file from an HTML file with an example?

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.

HOW include JSP file in another JSP?

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.

What is include tag in JSP?

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.


1 Answers

<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}"/> 
like image 150
Alex Avatar answered Sep 26 '22 21:09

Alex