Results 1 to 3 of 3
Thread: array passing dynamically
- 10-16-2008, 12:07 PM #1
array passing dynamically
Hi
Can anyone help me how to set and get an array attribute values??
Eg:
for(int i=0;i<array.length;i++)
{
session.setattribute(array[i],array[i]);
}
now i would like to get this array value in forwarded jsp???
thanksvisit : www.yoteam.co.cc
- 10-16-2008, 03:02 PM #2
OK create a class with name Constants,create in it the array which will be public and will have all the names for session attributes.
after that in jsp file you create the session variables:Java Code:package ourbeans; public class Constants { public static final String[] array = {"username","password"}; ...
In this way you can get attributes from the session:Java Code:<jsp:useBean id="constants" class="ourbeans.Constants" /> for(int i=0;i<constants.array.length;i++) { session.setattribute(array[i],array[i]); }
Java Code:session.getAttribute(cosntants.array[0]);
- 10-16-2008, 10:29 PM #3
A better coding style is to use constants to get at fixed position elements in an array. When you add a new element between two existing ones, there will be a simple coding change in one place, vs looking through your code to change all the hard coded indexes.session.getAttribute(cosntants.array[0]);
Java Code:... final int NameIdx = 0; // index to name ... session.getAttribute(cosntants.array[NameIdx]);
Similar Threads
-
[SOLVED] passing array between main and method,vice-versa
By blueyan in forum New To JavaReplies: 5Last Post: 10-04-2008, 11:13 AM -
passing data dynamically
By abhiN in forum Advanced JavaReplies: 1Last Post: 01-22-2008, 09:43 AM -
passing dynamically generated values
By abhiN in forum Advanced JavaReplies: 1Last Post: 01-20-2008, 03:21 AM -
passing an array into an instance
By lockmac in forum New To JavaReplies: 1Last Post: 08-08-2007, 09:35 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks