Solved

problem while retrieving 2D Array

Posted on 2004-10-01
3
238 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 1

Accepted Solution

by:
helloexpert earned 250 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

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!

Question has a verified solution.

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

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
We take a look at some of the most common obstacles that IT teams run into as they work relentlessly to keep all the alarms and sirens from going off at once.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

695 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