Question

Original JSP that works:

<c:forEach var="book" items="${books}" varStatus="bookIndex">
    <td>
        <jsp:include page="/includes/book_item.jsp?id=${book.id}&title=${book.title}&price=${book.price}&qty=${book.quantity}"/>
    </td>
</c:forEach>

This code is not written by me and I want to improve it so that I am passing ${book} to /includes/book_item.jsp but not a bunch of params.

However:

I cannot make /includes/book_item.jsp receive book passed. Why? What is wrong?

<jsp:include page="/includes/book_item.jsp">
    <jsp:param name="book" value="${books[i.index]}" />
</jsp:include>

OR

<jsp:include page="/includes/book_item.jsp">
    <jsp:param name="book" value="${book}" />
</jsp:include>

I tried to rename book passed in case naming conflicting. I am out of idea and trying on solve it cost me hours....

In /includes/book_item.jsp I tried to pass other EL param it works.

Was it helpful?

Solution

You can only pass strings as request parameters. Not objects.

You should probably transform the included page into a JSP tag file, accepting a book as attribute. Or you can store the book in a request attribute, and then include the JSP (which will get it from this request attribute)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top