Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JSTL problem

Reply
Thread Tools

JSTL problem

 
 
gk
Guest
Posts: n/a
 
      01-03-2006
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 ?

 
Reply With Quote
 
 
 
 
gk
Guest
Posts: n/a
 
      01-05-2006




anybody know JSTL here ?









gk wrote:

> 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 ?


 
Reply With Quote
 
 
 
 
Raymond DeCampo
Guest
Posts: n/a
 
      01-05-2006
gk wrote:
>
> anybody know JSTL here ?
>
> gk wrote:
>
>
>>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 ?

>


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

--
XML is the programmer's duct tape.
 
Reply With Quote
 
josh.s17@gmail.com
Guest
Posts: n/a
 
      01-05-2006
There are plenty of examples of how to use the forEach tag in this
tutorial.

http://www-128.ibm.com/developerwork...ry/j-jstl0318/

 
Reply With Quote
 
gk
Guest
Posts: n/a
 
      01-09-2006

> 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/developerwork...ry/j-jstl0318/

the code is :


<table>
<c:forEach items="${entryList}" var="blogEntry">
<tr><td align="left" class="blogTitle">
<cut value="${blogEntry.title}" escapeXml="false"/>
</td></tr>
<tr><td align="left" class="blogText">
<cut 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 ?

 
Reply With Quote
 
Raymond DeCampo
Guest
Posts: n/a
 
      01-10-2006
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}">

>
>
>
> 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/developerwork...ry/j-jstl0318/
>
> the code is :
>
>
> <table>
> <c:forEach items="${entryList}" var="blogEntry">
> <tr><td align="left" class="blogTitle">
> <cut value="${blogEntry.title}" escapeXml="false"/>
> </td></tr>
> <tr><td align="left" class="blogText">
> <cut 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

--
This signature intentionally left blank.
 
Reply With Quote
 
gk
Guest
Posts: n/a
 
      01-11-2006
>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

 
Reply With Quote
 
Raymond DeCampo
Guest
Posts: n/a
 
      01-11-2006
gk wrote:
>>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.
>


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

--
This signature intentionally left blank.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(struts/JSTL) Setting bean property value with jstl choose compoundresults DaFoot Java 1 10-23-2008 12:42 PM
Problem with interpolation of JSTL variables Lord0 Java 1 05-16-2005 09:20 PM
Basic jstl problem - Setting a bean property Bob Rivers Java 1 02-03-2005 05:33 PM
Custom JSTL that accepts JSTL expression Robert Mark Bram Java 0 12-15-2004 12:26 AM
JSTL problem, expressions not being evaluated in c:out Chris Java 1 01-09-2004 03:05 PM



Advertisments