1,105,375 Community Members

Unable to access an array of objects passed with request in jsp

Member Avatar
jimmyabhinav28
Newbie Poster
1 post since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I am parsing a file and populating a static array of objets in a servlet. Then i pass the static array and try to access the array in the jsp by using the JSTL <c:forEach> tag
in the loop i want to populate a table. I am perfectly able to access the array when I forward a request to another servlet

The structure of the class of objects is as shown here

public class servObjects
    {
        public String hostId;
        public String serverName;

        public servObjects(String string, String string0) {
            hostId=new String(string);
            serverName=new String(string0);
        }
    }

The servlet passes the array in a manner as shown below:

public static servObjects ServArr[];
   ServArr=new servObjects[serverlinescount];
  for(int j=0;j<serverlinescount;j++)
            {
              ServArr[j]=new servObjects(serverNamesArr[j],hostIdArr[j]);
               
             //out.println("SERVER:    "+ServArr[j].serverName+"     "+ServArr[j].hostId+"<br>");
            }
 request.setAttribute("sna", LicenseFileParser.ServArr);
RequestDispatcher rd=getServletContext().getRequestDispatcher("/UpdateLicense.jsp");
          rd.forward(request, response);

This is what i do in the JSP page

<TABLE id="ServerTable" width="350px" border="1">
        <tr>
            <th>select</th>
            <th>serial number</th>
            <th>host Id</th>
           <th>server name</th>
        </tr>
       <c:forEach var="items1" begin="0" items="${requestScope.sna}">
        <TR>
            <TD><INPUT type="checkbox" name="chk[]"/></TD>
            <TD> 1 </TD>
            <TD> <INPUT type="text" name="hostids[]" value="${items1.hostId}"/> </TD>
            <TD> <INPUT type="text" name="servernames[]" value="${items1.serverName}" /> </TD>
        </TR>
        </c:forEach>
       
      
        
        
    </TABLE>

Can anyone tell me where am i going wrong, and what may be other issues if this is correct? A sincere thanks to everyone who helps, in advance!

Member Avatar
ejosiah
Junior Poster
196 posts since Feb 2008
Reputation Points: 4 [?]
Q&As Helped to Solve: 23 [?]
Skill Endorsements: 3 [?]
 
0
 

You haven't actually told us if there is anything wrong with your program. I've you tested it and is it working as expected?

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: