Solved

problem while retrieving 2D Array

Posted on 2004-10-01
3
233 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
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse problems view not showing all the time 4 88
love6 challenge java 31 133
thymeleaf natural templating vs JSP 2 137
web application structure 18 101
Learn how to PXE Boot both BIOS & UEFI machines with DHCP Policies and Custom Vendor Classes
The advancement in technology has been a great source of betterment and empowerment for the human race, Nevertheless, this is not to say that technology doesn’t have any problems. We are bombarded with constant distractions, whether as an overload o…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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