Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

JSTL problem

Thread view: 
gk - 03 Jan 2006 06:42 GMT
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 ?
gk - 05 Jan 2006 04:30 GMT
anybody know JSTL here ?

> i have put an arraylist in  session in my servlet class.
>
[quoted text clipped - 10 lines]
> 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 ?
Raymond DeCampo - 05 Jan 2006 16:00 GMT
> anybody know JSTL here ?
>
[quoted text clipped - 12 lines]
>>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

Signature

XML is the programmer's duct tape.

gk - 09 Jan 2006 13:09 GMT
> 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:out value="${blogEntry.title}" escapeXml="false"/>
   </td></tr>
   <tr><td align="left" class="blogText">
     <c:out 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 ?
Raymond DeCampo - 10 Jan 2006 03:34 GMT
>>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
[quoted text clipped - 30 lines]
> 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

Signature

This signature intentionally left blank.

gk - 11 Jan 2006 06:41 GMT
>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
Raymond DeCampo - 11 Jan 2006 20:11 GMT
>>No; I only brought up the session scope because you used it in your OP
>
[quoted text clipped - 40 lines]
> 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

Signature

This signature intentionally left blank.

josh.s17@gmail.com - 05 Jan 2006 19:55 GMT
There are plenty of examples of how to use the forEach tag in this
tutorial.

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.