Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

problem while retrieving 2D Array

Posted on 2004-10-01
3
Medium Priority
?
250 Views
Last Modified: 2010-04-01
        i had 3 rows and 3 cols in the UI forum ;
          i am creating 2 dimensional array in jsp  and assigning requests to 2D array and after that storing into session object;

        when i retrive the session object i am getting only last value from 2D array i.e [3,3] parameter value;

        what wrong did i made in the below code

      String formData[][] = null  ;


              for(int i=1;i<4;i++)
          {
                  for(int j=1;j<4;j++)
                {
                  
           if(request.getParameter("mytextbox"+i+j+"_"+pageNumber) != null && !"".equals(request.getParameter("mytextbox"+i+j+"_"+pageNumber)))
                    {
                        formData =new String[4][4];
                        formData[i][j] = request.getParameter("mytextbox"+i+j+"_"+pageNumber);
                    }

                }
          }
                session.setAttribute("myFormDataForPage"+pageNumber, formData);


 if(session.getAttribute("myFormDataForPage"+pageNumber) != null  &&  !"".equals(session.getAttribute("myFormDataForPage"+pageNumber)))
      {
      
         formData =(String[][])session.getAttribute("myFormDataForPage"+pageNumber);
       for(int i=1;i<4;i++)
              {
              for(int j=1;j<4;j++)
                  {
            System.out.println("session values in controllerrrrrrrrrrr="+formData[i][j]);
                  }
              }
    }  
0
Comment
Question by:chaitu chaitu
1 Comment
 
LVL 1

Accepted Solution

by:
helloexpert earned 1000 total points
ID: 12201070
You are resetting the array every time in the nested for loop.

formData =new String[4][4];

this must be moved out of the two 'for' loops.

i.e instead of doing
String formData[][] = null  ;
you could do
String formData[][] =new String[4][4];
and then in the for loops
for (i...
  for (j...

           . . . ..

              formData[i][j] = request.getParameter("mytextbox"+i+j+"_"+pageNumber);

    . . . .

  }
}
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Applications for our next round of the Experts Exchange Scholarship Contest are starting to roll in. It made us wonder what our past winners are up to these days. Here's a look at what four winners experienced with the contest and what they're doing…
Last month Marc Laliberte, WatchGuard’s Senior Threat Analyst, contributed reviewed the three major email authentication anti-phishing technology standards: SPF, DKIM, and DMARC. Learn more in part 2 of the series originally posted in Cyber Defense …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Integration Management Part 2

810 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