paygo
asked on
JSTL HOW TO read through / iterate through a multi dimensional array - session object
Hello Everyone,
I'm looking for information on how to ' read through ' or ' iterate through ' a session / request object
- that is a multi-dimentional array.
->here's the object example:
public void class Elements
{
String sFirstElement;
Int iSecondElement;
long lThirdElement;
}
->here's the array of elements:
Elements [] arrayOfElements = new Elements[10];
~~~~~~ 'arrayOfElements' is loaded correctly here
-> arrayOfElements is placed in a session variable:
session.setAttribute("theS essionArra yOfElement s", arrayOfElements);
->> Here's where I get stuck (from a JSP Page)
<c:forEach ????="${sessiontScope.???? ??????}" var="????">
<c:out value="${?????.????}" escapeXml="false"/>
</c:forEach>
---------------Thanks for the help
I'm looking for information on how to ' read through ' or ' iterate through ' a session / request object
- that is a multi-dimentional array.
->here's the object example:
public void class Elements
{
String sFirstElement;
Int iSecondElement;
long lThirdElement;
}
->here's the array of elements:
Elements [] arrayOfElements = new Elements[10];
~~~~~~ 'arrayOfElements' is loaded correctly here
-> arrayOfElements is placed in a session variable:
session.setAttribute("theS
->> Here's where I get stuck (from a JSP Page)
<c:forEach ????="${sessiontScope.????
<c:out value="${?????.????}" escapeXml="false"/>
</c:forEach>
---------------Thanks for the help
You can try below in jsp:
<%@ page import="com.Elements" %>
<%
Elements [] arrayOfElements = new Elements[10];
session.setAttribute("theS essionArra yOfElement s", arrayOfElements);
//You can set it to session in other page
%>
<c:forEach var="elemnet" items="${sessionScope.arra yOfElement s}">
<c:out value="${element.sFirstEle ment}" escapeXml="false"/>
</c:forEach>
<%@ page import="com.Elements" %>
<%
Elements [] arrayOfElements = new Elements[10];
session.setAttribute("theS
//You can set it to session in other page
%>
<c:forEach var="elemnet" items="${sessionScope.arra
<c:out value="${element.sFirstEle
</c:forEach>
Oh,sorry
items="${sessionScope.arra yOfElement s}"
should be
items="${sessionScope.theS essionArra yOfElement s}"
items="${sessionScope.arra
should be
items="${sessionScope.theS
ASKER
Ok - thanks.
Here's the trick. I'm using struts
A - the elements are defined in on class
public void class Elements
{
String sFirstElement;
Int iSecondElement;
long lThirdElement;
}
B - The controller (a different class ) creates the array
and places the filled array in request scope:
Elements [] arrayOfElements = new Elements[10];
session.setAttribute("theS essionArra yOfElement s", arrayOfElements);
C- Problem is when I use
<c:forEach var="element" items="${sessionScope.theS essionArra yOfElement s}">
<c:out value="${element.sFirstEle ment}" escapeXml="false"/>
</c:forEach>
>>>>> The message is element 'sFirstElement' can not be found.
--thanks - I think this is pretty close toa solution
Here's the trick. I'm using struts
A - the elements are defined in on class
public void class Elements
{
String sFirstElement;
Int iSecondElement;
long lThirdElement;
}
B - The controller (a different class ) creates the array
and places the filled array in request scope:
Elements [] arrayOfElements = new Elements[10];
session.setAttribute("theS
C- Problem is when I use
<c:forEach var="element" items="${sessionScope.theS
<c:out value="${element.sFirstEle
</c:forEach>
>>>>> The message is element 'sFirstElement' can not be found.
--thanks - I think this is pretty close toa solution
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
HI koppcha
I am trying to avoid using beans, getters and setter etc. I just want to use a generic class to hold the elements.
I'm thinking this - I can pass a value into session object from any class
i.e. session.SetAttibute("nowIn Session" anyValue);
I can also retrieve that session variable from any JSP Page.
i.e. <c:out sessionScope=${"nowInSessi on"} />
Now with and Array - I understand you need to use the:
<c:forEach var="element" items="${requestScope.theS essionArra yOfElement s}">
<c:out value="${element.sFirstEle ment}" escapeXml="false"/>
</c:forEach>
- But the element 'sFirstElement' can not be found message appears.
thanks
I am trying to avoid using beans, getters and setter etc. I just want to use a generic class to hold the elements.
I'm thinking this - I can pass a value into session object from any class
i.e. session.SetAttibute("nowIn
I can also retrieve that session variable from any JSP Page.
i.e. <c:out sessionScope=${"nowInSessi
Now with and Array - I understand you need to use the:
<c:forEach var="element" items="${requestScope.theS
<c:out value="${element.sFirstEle
</c:forEach>
- But the element 'sFirstElement' can not be found message appears.
thanks
ASKER
Here's the answer -
public void class Elements
{
String sFirstElement;
Int iSecondElement;
long lThirdElement;
<Add this>
public String getSFirstElement()
{
return sFirstElement;
}
<end>
}
point go to koppcha for the tip off thanks - don't need to use a bean though
public void class Elements
{
String sFirstElement;
Int iSecondElement;
long lThirdElement;
<Add this>
public String getSFirstElement()
{
return sFirstElement;
}
<end>
}
point go to koppcha for the tip off thanks - don't need to use a bean though
In JSP
<jsp:useBean id='MyBean' class='com.koppcha.MyBean'
<c:forEach var='name' items='${sessionScope.MyBe
FirstElement is: '<c:out value='${name.sFirstElemen
SecondElement is: <c:out value='${name.iSecondEleme
ThirdElement is: <c:out value='${name.lThirdElemen
</c:forEach>
Hope this helps .You can check this link aswell
http://www.phptr.com/articles/article.asp?p=30946&seqNum=4