I wanted to pass a List type object which is in the main JPS to an include JSP ( jsp:include). Since the parm only support strings, I cannot use the parm tag to pass List type data to the include file.
Uses examples:
<jsp:include page="/jsp/appList.jsp">
<jsp:param name="applications" value="${applications}"/>
</jsp:include>
Or:
<jsp:include page="/jsp/appList.jsp">
<jsp:param name="applications" value="${confirmed_applications}"/>
</jsp:include>
<jsp:include page="/jsp/appList.jsp">
<jsp:param name="applications" value="${unconfirmed_applications}"/>
</jsp:include>
<jsp:include page="/jsp/appList.jsp">
<jsp:param name="applications" value="${canceled_applications}"/>
</jsp:include>
I could create a Simple Tag Handler but I would like to know if there is an easier way.
The <jsp:include> tag lets you pass parameters to the include file—a useful capability if your application takes user input. In this example, the server retrieves the form values with the request. getParameter() method and writes them in the <jsp:param> tags.
You could use javascript/jquery to pass the values from the first form to the hidden fields of the second form. Then you could submit the form. Or else the easiest you could do is use sessions.
Agree with ChssPly76 that its probably a sign of trouble if the List is being generated in the JSP, but another alternate approach to get the object to the other JSP is to add it to the HttpServletRequest objects attribute field using a scriplet:
JSP with the List:
<%
request.setAttribute("theList", ListObject);
%>
The other JSP:
<%
List myList = (List) request.getAttribute("theList");
%>
This is indeed what jsp tags are meant for. You create a .tag file that accepts attributes (not parameters), which can be of arbitrary type.
See this article for a good tutorial.
"Params" are analogous to the parameters you see in an HTTP query (the part of the URL following the '?').
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