Moving Variable from one form to the next

Posted on 2004-11-13
Last Modified: 2010-04-01
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!!!!!!!
Question by:VbMonk
    LVL 14

    Accepted 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
    LVL 11

    Expert Comment

    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

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
    DECT technology has become a popular standard for wireless voice communication. DECT devices are not likely to be affected by other electronic devices and signals because they operate in a separate frequency-band.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now