Array List

Hi,

I am new to Java.I want a solution for my problem.

Scenario for my problem is:

My project is in Healthcare.I want to "add multiple dependents" thru a jsp. A dependent has various fields such as Name,Age,Address,Sex etc. Plz tell me how to get these values from jsp to servlet so that I can update the database for the given values.

Do I need to use vector or Arraylist?

If yes,plz tell how to use it and how to iterate?

Thanks

[474 byte] By [shailu_ta] at [2007-11-27 3:48:16]
# 1

u just simply submit in jsp and take it in servlet via

request.getParamter("fieldname");

for ex:

in jsp

******

sending name=vijay to servlet

in servlet

public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException

{

try

{

//connection line...

...

....

statementobject.executeUpdate("insert into tablename values ('" + req.getparameter("name") +"', .........

}

catch(SQLException e){}

....

.....

}

drvijayy2k2a at 2007-7-12 8:52:09 > top of Java-index,Java Essentials,New To Java...
# 2
Plz tell me what to do if I have scenario like this--name1= shailuage1=22sex1=mname2=amitage2=23sex2=mand so on..then how to get these values from jsp to servlet and insert into database?plz tell me.
shailu_ta at 2007-7-12 8:52:09 > top of Java-index,Java Essentials,New To Java...
# 3

1->use some dtml stuff to add the rows dynamically in the jsp. Make sure that you generate the names of the fields unique like when you are looping, use the incremental value to append to the variable name.

2-> when you submit the form, in a java script function, create a custom string from the values from the jsp page like name1=sailu~age1=22~sex1=m^name2=amit~age2=23~sex2=m

3->send this value to your servlet, you can use a hidden param or your wish.

4->tokenize this in the servlet and add to the database.

(PS: This may not be the optimal solution)

Teja_Chaitu_Kantamnenia at 2007-7-12 8:52:09 > top of Java-index,Java Essentials,New To Java...