JSTL problem

G

gk

i have put an arraylist in session in my servlet class.

session.setAttribute("list",L);




i want to use this arrayList in my JSP page to display the list items.

i want to use JSTL c:forEach for this purpose.


How do i get the arrayList in JSP page ?




List RetrievedList =(java.util.List)session.getAttribute("list");

should use this code in my JSP before using the c:forEach tag.
otherwise how does my c:forEach gets the list from the servlet ?
 
R

Raymond DeCampo

gk said:
anybody know JSTL here ?

gk wrote:

Just enough to be dangerous. I think that want you want to do is enable
the JSP expression language which will allow you to use constructs like
(untried and untested)

<c:forEach var="x" items="${sessionScope.list}">

If you need more information, I suggest looking at the J2EE tutorial on
http://java.sun.com.

HTH,
Ray
 
G

gk

Just enough to be dangerous. I think that want you want to do is enable
the JSP expression language which will allow you to use constructs like
(untried and untested)

<c:forEach var="x" items="${sessionScope.list}">


OK. so, you meant , in the Action class, should use
session.setAttribute("list")

And in the JSP, i would pick up this way "<c:forEach var="x"
items="${sessionScope.list}">"

i see, you are using the "sessionScope" keyword.

BUT look at this examle here

http://www-128.ibm.com/developerworks/java/library/j-jstl0318/

the code is :


<table>
<c:forEach items="${entryList}" var="blogEntry">
<tr><td align="left" class="blogTitle">
<c:eek:ut value="${blogEntry.title}" escapeXml="false"/>
</td></tr>
<tr><td align="left" class="blogText">
<c:eek:ut value="${blogEntry.text}" escapeXml="false"/>
</td></tr>
</c:forEach>
</table>


did you see, they are not using "sessionScope" as you given in your
example !!! How they are accessing the list then ....is this code
wrong ?
 
R

Raymond DeCampo

gk said:
OK. so, you meant , in the Action class, should use
session.setAttribute("list")

And in the JSP, i would pick up this way "<c:forEach var="x"
items="${sessionScope.list}">"

i see, you are using the "sessionScope" keyword.

BUT look at this examle here

http://www-128.ibm.com/developerworks/java/library/j-jstl0318/

the code is :


<table>
<c:forEach items="${entryList}" var="blogEntry">
<tr><td align="left" class="blogTitle">
<c:eek:ut value="${blogEntry.title}" escapeXml="false"/>
</td></tr>
<tr><td align="left" class="blogText">
<c:eek:ut value="${blogEntry.text}" escapeXml="false"/>
</td></tr>
</c:forEach>
</table>


did you see, they are not using "sessionScope" as you given in your
example !!! How they are accessing the list then ....is this code
wrong ?

No; I only brought up the session scope because you used it in your OP.
There is a sequence of scopes that the expression language (EL) will
search through to find variable values. Unless you have an explicit
need for another scope, I think that the request attribute will fill
your needs.

If you are serious about using JSTL you should try to obtain a resource
that will help you understand it. Don't expect to simply jump right in
and have everything be easy. The J2EE tutorial on http://java.sun.com
has many examples.

HTH,
Ray
 
G

gk

No; I only brought up the session scope because you used it in your OP

OK...thats correct.

but How those guys (the code i posted from IBM tutorial) are doing it
then ?

How they are accessing the list ?

they are using this...
<c:forEach items="${entryList}" var="blogEntry">

did you see, they are NOT using session scope,page scope,application
scope ..nothing !......how they are picking up the data in the JSP ?

How is this entryList picked up ?

There is a sequence of scopes that the expression language (EL) will
search through to find variable values. Unless you have an explicit
need for another scope, I think that the request attribute will fill
your needs.


suppose, i have put the list in the session scope in the Action class.

Now, how the JSTL would find it ?

Now, if i have <c:forEach items="${entryList}" var="blogEntry">


scan 1: the JSTL first scan request scope whether the lis is there or
not....if it fails

scan 2: the JSTL would scan session scope whether the lis is there or
not....if it fails

scan 3: the JSTL would scan page scope whether the lis is there or
not.....if it fails

scan 4: the JSTL would scan application scope whether the lis is
there or not.....

IF all of them fails, then NULL pointer exception.

is this approach JSTL follows while searching a list when no scope is
specified in the JSP.

thank you
 
R

Raymond DeCampo

gk said:
OK...thats correct.

but How those guys (the code i posted from IBM tutorial) are doing it
then ?

How they are accessing the list ?

they are using this...
<c:forEach items="${entryList}" var="blogEntry">

did you see, they are NOT using session scope,page scope,application
scope ..nothing !......how they are picking up the data in the JSP ?

How is this entryList picked up ?






suppose, i have put the list in the session scope in the Action class.

Now, how the JSTL would find it ?

Now, if i have <c:forEach items="${entryList}" var="blogEntry">


scan 1: the JSTL first scan request scope whether the lis is there or
not....if it fails

scan 2: the JSTL would scan session scope whether the lis is there or
not....if it fails

scan 3: the JSTL would scan page scope whether the lis is there or
not.....if it fails

scan 4: the JSTL would scan application scope whether the lis is
there or not.....

IF all of them fails, then NULL pointer exception.

is this approach JSTL follows while searching a list when no scope is
specified in the JSP.

It is something like that. I can't confirm a couple of things above,
but you have the general idea. Either dig through the specs or write
some examples to flesh out the other parts.

I don't know what the specific order is for searching the scopes. I
would imagine that page scope comes before session scope however. I
also can't confirm what the behavior is when the data is not found. I
would hope for a regular subclass of Exception, not
NullPointerException, which extends RuntimeException.

HTH,
Ray
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

JSTL Question 10
View page without JSTL 2
JSTL attempt in JSP 5
JSTL newbie question 3
JSTL database access 0
Beyond trivial JSTL 1
Beginner's JSTL Problem 0
problem upgrading to JSTL 1.2 11

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top