Accessing an ArrayList of objects in JSP

I've got an ArrayList of Product items created in a servlet and passed into a jsp that I need to display in the jsp. Can someone point me to a howto on this or some examples that show how to iterate through the list and display the fields of the Product objects stored in the ArrayList? I'm not particularly familiar with Beans yet so I will be reading up on that. Thanks.

Ok, I installed Taglibs and set up 'core' to be part of my web app. Now I made a little test jsp. I have a class called "Customer" in my WEB-INF/classes folder (and sources of course), "results" is an ArrayList of Customer objects that is stored in the session:

But I'm getting the "cannot be resolved to a type error" on my "Customer" class which is sitting in the WEB-INF/classes folder.

To easily isolate the problem, you may want to create a package for the Customer class (i.e., do not use default package) and you may want to include it in the list of imports in your JSP page directive.

You don't need any <jsp:usebean> or <%@ page import%> tags for this. At some point before displaying this JSP you need to put the ArrayList in the session like this:

Then in your JSP, all you need is:

Lido Collins
Greenhorn

Joined: Apr 27, 2006
Posts: 20

posted Apr 30, 2006 18:13:00

0

Wouldn't I need a bean to handle the fact that Customer is an object?

Now I think I have a problem with my jstl installation. I redeployed my war file and had to copy the two jars into the lib folder and the .tld files into the WEB-INF file and I'm not sure it's working. Here's my new test file based on your suggestion:

I'm using Tomcat 5, and I think it's JSTL 1.1.2 which when I downloaded said it would work with jsp/servlets under Tomcat 5 because all containers are compatible (something like that). Also, the standard-examples are working... I even tried copying the standard-examples web.xml <web-app> tag. Commenting this out:

Ok, if you have Tomcat 5, then that last change should almost be enough. The ony remaining change would be to put <jsp-config> around those taglib definitions in web.xml. At that point all should start working.

Also note that taglib entries for JSTL are NOT necessary, and in fact can create problems. All you need to use the JSTL tags are the two jar files in WEB-INF/lib (standard.jar, jstl.jar) - No tld files - No entries in web.xml

Lido Collins
Greenhorn

Joined: Apr 27, 2006
Posts: 20

posted Apr 30, 2006 20:42:00

0

Thanks, but that didn't help. Still getting the same output. I tried taking the .tld files out of the directory and taking the <taglib> section out of web.xml first, but that didn't work. Then I put the tld files back, added the <taglib> section back into the web.xml file and then put the <jsp-config> tags around that, still no change.

The other trick is to try this at the top of your jsp page: <%@ page isELIgnored="false" %>

If you have web.xml set up correctly, you shouldn't need this, but it might be worth a try.

Eduardo Dela Rosa
Greenhorn

Joined: Apr 15, 2004
Posts: 25

posted May 01, 2006 18:23:00

0

Hi,

I don't actually see problem with your taglib directives, nor taglibs in web descriptor file, but if you're getting the same problem, i.e., invalid Customer object, try looking back at your 17th post.

Is it right that you moved your Customer class to "storePackage"?... then why did you declare a "com.storePackage.Customer" class in your <jsp:useBean> action tag when it should only be "storePackage.Customer" (whithout the com)?

But please ignore this if you already have restructured your codes then. It's just a thought of the past.

Lido Collins
Greenhorn

Joined: Apr 27, 2006
Posts: 20

posted May 01, 2006 20:00:00

0

Yes, I have that web-app tag instead of the DTD etc tag in web.xml. I will try that line in the jsp and see what happens. I will also double check the package situation. Thanks.