aspose file tools*
The moose likes JSP and the fly likes ArrayList in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "ArrayList in JSP" Watch "ArrayList in JSP" New topic
Author

ArrayList in JSP

Daniel Gultom
Greenhorn

Joined: Aug 01, 2007
Posts: 6
can JSP use ArrayList?

i have this code in my servlet.


then of course i want to get the result and use the request.getAttribute("result") in my JSP page.

but the thing is JSP seems like not knowing ArrayList
i use this code

but it doesn't work. I use Eclipse v3.3 and the JDK 1.5.
The eclipse return "ArrayList cannot be resolved to a type"

Please someone help me.
Appreciate the help. Thanks in advance.
Herman Schelti
Ranch Hand

Joined: Jul 17, 2006
Posts: 387
hi Daniel,

does your servlet have an import statement for ArrayList?
(does your JSP have one too?)

Herman
Daniel Gultom
Greenhorn

Joined: Aug 01, 2007
Posts: 6
ow...
i have import statement in my servlet
but not on my jsp. so that is the problem. forget to write these
<%@ page import="java.util.ArrayList" %>

i finally able to use the ArrayList but the problem is i need to
print the String in the ArrayList.

my code is

the thing is request.getAttribute must be an Object.
I try to cast it so that it become ArrayList.
however it returns java.lang.NullPointerException

can anyone solve the problem please.
thanks in advance.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

This isn't something that someone on a list of forum can help you with.
This is basic debugging.

If getAttribute is returning null, then you need to examine the code that binds "result" to request scope. Also, remember, that request, as its name suggests, is only good for one request/response cycle. If you bind something to request scope and then try to retrieve it in another request, you will get a null result.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Herman Schelti
Ranch Hand

Joined: Jul 17, 2006
Posts: 387
hi,

did you check (in your servlet) that result = card.view(parameter); is OK?
try to log how many items you have in your ArrayList.

Herman
Daniel Gultom
Greenhorn

Joined: Aug 01, 2007
Posts: 6
i have solved the problem. thank you for all the assistance
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Daniel Gultom:
i have solved the problem. thank you for all the assistance


What was it?
 
Don't get me started about those stupid light bulbs.
 
subject: ArrayList in JSP