?
Solved

problem while retrieving 2D Array

Posted on 2004-10-01
3
Medium Priority
?
243 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 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
Hey fellow admins! This time, I have a little fairy tale for you. As many tales do, it starts boring and then gets pretty gory. I hope you like it. TL;DR: It is about an important security matter, you should read it if you run or administer Windows …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month14 days, 2 hours left to enroll

800 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