jGuru Forums

creating a collection
1 posts in topic
Flat View
TOPIC ACTIONS:

Posted On:   Tuesday, August 5, 2003 04:20 AM

I have created a form that will take four int values entered by a user and what I would like to do is to return a list of data that match the result criteria. so for example, the user enters the following in the form: a = 5, b=4, c=3, d=9, and the system will return name || a || b || c || d || ============================== Hans || 5 || 4 || 3 || 9 || Liam || 5 || 4 || 3 || 9 || etc. now I have designed the jsp page I have ensured that it validates the inputs form the user, I have been told to 1. Create a TreeMap 2. Create a 'four-slot' Vector 3. Fill the Vect   More>>

I have created a form that will take four int values entered by a user and what I would like to do is to return a list of data that match the result criteria.

so for example, the user enters the following in the form:

a = 5, b=4, c=3, d=9,

and the system will return

name || a || b || c || d ||

==============================

Hans || 5 || 4 || 3 || 9 ||

Liam || 5 || 4 || 3 || 9 ||

etc.

now I have designed the jsp page I have ensured that it validates the inputs form the user, I have been told to

1. Create a TreeMap

2. Create a 'four-slot' Vector

3. Fill the Vector with random numbers

4. Add the Vector to the map with the name as the key

how would I go about this and how would I return the result?    <<Less

Re: creating a collection

Posted By:   Anonymous
Posted On:   Friday, August 8, 2003 12:06 AM

Perhaps i don't understand properly your message, but if you just want to read user-name and four int, just create a class that contains the following information

`public class XXXX {     private String userName;     private int [] userInput;     ...     ...}`

From JSP page just print the information that you are saving on that class.

The class is just a way to save this information in a place (session) in a proper manner. If you aren't planning to pass this information to request, session or context, the class isn't really needed.

Of course you can use a TreeMap with Vector (or List) values, but i don't see the need to use it (mantaining all user information in context????, maintaining an historic of user input???). In this case, you just need to save in the TreeMap the array of ints (no vector, nor List).

`TreeMap tr = new TreeMap();String userName = XXX;int [] userInput = int [] {1,2,3,4};tr.put(userName,userInput)...int [] result = (int [])tr.get(userName);`