[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

Moving Variable from one form to the next

My 2 forms (one with a submit button) work well in passing values of variables in one page to the next. Page1.jsp has input text controls and Page2.jsp does not have form controls. In this situation, I can play around with variables obtained from page1.jsp in page2.jsp.

I decided to put a form button control and one input text control in page2.jsp. What now happens is that I can get the variables from page1 but when I click the submit button I included in page2.jsp, the values of the variables turn to 'null'. I have verified this using out.println statements. my code is as follows:
String Page1Input = request.getParameter("Index");
out.println(Page1Input); //produces the results but when button is clicked, it turns to 'null'

I want to use Page1Input in the code when button in page2.jsp is clicked. It seems like the submit button refreshes page2.jsp so that I lose the obtained data.
How can I resolve this??
Please help!!!!!!!
1 Solution
Each page submit/click is a new request, so parameters in request can't pass across multiple pages.

You either put hidden field in page2.jsp to store the value from page1.jsp or store the value from page1.jsp in HttpSession and use session to carried the value across multiple pages.

Boon Leng
Yes. Using session to keep variable along multiple pages.

Here are some useful code.

//To put variable to session
String temp = "Hello World";
session.setAttribute("name", temp);

//To get variable from session
String str = (String)session.getAttribute("name");


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now