Solved

problem while retrieving 2D Array

Posted on 2004-10-01
3
228 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
3 Comments
 
LVL 1

Accepted Solution

by:
helloexpert earned 250 total points
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
HOW TO: Connect to the VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere (HTML5 Web) Host Client 6.5, and perform a simple configuration task of adding a new VMFS 6 datastore.
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

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

14 Experts available now in Live!

Get 1:1 Help Now