Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList in JSP

 
Daniel Gultom
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 387
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Daniel,

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

Herman
 
Daniel Gultom
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Herman Schelti
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have solved the problem. thank you for all the assistance
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Daniel Gultom:
i have solved the problem. thank you for all the assistance


What was it?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic