Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple doubt on getAttribute

 
midhun raj
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet called newservlet.java
and a jsp called Uupdate.jsp

in newservlet.java


in Uupdate.jsp

I get the error...


but if i use Ulist in the places of Uattribute it works fine ... where am i going wrong

Thank you
in advance
 
viv shah
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check your UJList.size()
It might be that you are iterating more than records you have in your list
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch..
It seems like either the Session attribute is not setting up..or there is some problem in the for loop
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this and check what you are getting from the set attribute..





for the time being comment the complete for loop
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64972
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, you should not have any Java code in your JSP. Period.

Secondly, your loop logic is really odd and very likely trying to access elements outside of the vector (Vector? Why not a List?).

The problem isn't with getAttrribute() but with your understanding of loops.
 
Souvvik Basu
Ranch Hand
Posts: 96
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Midhun, welcome to the ranch.



# for(int i=0;i<UJList.size();i=i+3)
# {
# out.println(UJList.elementAt(i));
# out.println(UJList.elementAt(i+1));
# out.println(UJList.elementAt(i+2));
#
# }


This is what your loop seems to be doing.....
UJList.size() should be 3, since you are adding 3 items. On first iteration, i=0, so you are printing
That should pretty much print all your items in the vector. Why use a loop then? Also, for next iteration, i becomes 3, and it should exit the loop since condition is i<3
are you sure your loop is doing what you wanted it to do?

Also, what is the object rs ?? There is no mention of it here. If there is a problem with rs, the vector may not get populated at all, and throw NullPointerException
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic