File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Getting parameters/attributes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Getting parameters/attributes" Watch "Getting parameters/attributes" New topic

Getting parameters/attributes

Carol Murphy
village idiot

Joined: Mar 15, 2001
Posts: 1202
(This is for a Cattle Drive assignment, so technically you're not helping me with homework!)

I am coding a servlet class that gets input from a form, creates an object using that input ( there are 6 parameters needed to create the object ) and puts it into an ArrayList. This servlet class also needs to provide a way to access the objects in the ArrayList and send the values stored for each of the six attributes to a jsp where they will be displayed in a table.
I've got everything working <b>except</b> only the last object in the ArrayList is being displayed in the table.
I've been going around in circles until I'm dizzy trying to figure out how the attributes in the request object are sent from the servlet class to the jsp, and exactly what is in that response.
I can't figure out if the problem is in my servlet class, where the code for setting the attributes for the request object is part of a for block that iterates through my ArrayList, getting each object and setting the 6 attributes for each, and when the block completes, forwards the whole thing to the jsp, where only the last object is being printed in the table; <b>or</b> in the jsp itself, where the code for printing out the table data might be faulty (i.e. it only prints one row of the table, rather than iterating through the who;e list list).
How can I check to see what is being forwarded with the response from the servlet to the jsp?
[ May 01, 2006: Message edited by: Bear Bibeault ]
Stefan Evans

Joined: Jul 06, 2005
Posts: 1580
Does it print only one line in the table, or does it print multiple lines, but all the same values?

So many potential places for trouble.
Here are a couple of common mistakes I have seen

1 - Putting/editing the same object into the arraylist

The problem with the above code, is that only one instance of the user object is created, and the loop overrides the values each time.
So you end up with the same object in the list multiple times.
To fix - the line "user = new User()" needs to be added in the loop.

2 - scope issues.
You say it is in request scope. Request scope attributes only last for one request/response (ie one page) every click of a link/button is a new request
Maybe the list needs to be kept in session scope, so that it retains all the items added in this session?

Well thats my shot in the dark as to your problem. To be of more help, we'll have to see some code.
I agree. Here's the link:
subject: Getting parameters/attributes
It's not a secret anymore!