-3

How can I pass multiple user entries from one JSP to other JSP pages? Example I enter numbers 2, 3, 4, 5 in different input boxes and hit submit. I know that on the next page, the numbers will be there but on third one they will not.

Thank you!

Silvestrini
  • 445
  • 4
  • 19

2 Answers2

6

once you key in details on first page and you want them to 2nd page you can use getparam(). If you want share the variable in multiple pages, you can use setAttribute()

Example :

A.jsp

<input type="text" name="name" value="">
<input type="text" age="age" value="">

B.jsp

String sNAME =  request.getParameter("name");
String sAGE  = request.getParameter("age");

session.setAttribute("SES_NAME",sNAME);
session.setAttribute("SES_AGE",sAGE);

C.JSP / D.JSP / E.JSP / F.JSP and so on

 String NAME =    session.getAttribute("SES_NAME"));
 String AGE  =    session.getAttribute("SES_AGE"));
user3835327
  • 1,194
  • 1
  • 14
  • 44
1

A common approach is to put the values from the first page in to the second page as hidden fields. That way they will not be visible to the user, but will still be passed to your third page with the second form.

Depending on your use case you might not want to send the data back and forth like that, in which case you can store it in the session, or in your database.

Community
  • 1
  • 1
James Waddington
  • 2,894
  • 2
  • 15
  • 24
  • I know about the hidden technic and the session. But I mean like user types in the info, and that info must appear 3 JSP pages later. :S – Silvestrini Jan 30 '15 at 18:59
  • 1
    user types the info, you save it in session, 2 pages later, you retrieve it. You say you know the technics.... use them? or do you expect us to write your code for you? – Patrice Jan 30 '15 at 19:09
  • No, I dont really expect you to write me the code. Im asking for tips, NOT the code. Thank you. – Silvestrini Jan 30 '15 at 19:12
  • @Silvestrini well... the tips are session, hidden fields.... what more do you want? I don't understand. These techniques are EXACTLY what you need. what more are you expecting from this? – Patrice Jan 30 '15 at 19:14