Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass a List to another jsp file

Tags:

java

jsp

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.

like image 680
Sergio del Amo Avatar asked Oct 08 '09 16:10

Sergio del Amo


People also ask

How can you pass information from one jsp to included jsp?

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.

How can I pass values from one JSP page to another jsp without submit button?

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.


2 Answers

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");
%>
like image 164
Tobias M Avatar answered Sep 25 '22 13:09

Tobias M


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 '?').

like image 40
Jonathan Feinberg Avatar answered Sep 25 '22 13:09

Jonathan Feinberg