File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes simple doubt on getAttribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "simple doubt on getAttribute" Watch "simple doubt on getAttribute" New topic

simple doubt on getAttribute

midhun raj

Joined: Jun 04, 2011
Posts: 10
I have a servlet called
and a jsp called Uupdate.jsp


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

Joined: Apr 21, 2011
Posts: 3
Check your UJList.size()
It might be that you are iterating more than records you have in your list
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Welcome to JavaRanch..
It seems like either the Session attribute is not setting up..or there is some problem in the for loop

SCJP6.0,My blog Ranchers from Delhi
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

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

Joined: Jan 10, 2002
Posts: 63870

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.

[Asking smart questions] [About Bear] [Books by Bear]
Souvvik Basu
Ranch Hand

Joined: Apr 05, 2010
Posts: 96

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

OCJP 6.0
I agree. Here's the link:
subject: simple doubt on getAttribute
It's not a secret anymore!