This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
I have to retrieve list of statesfrom the database and populate it in the drop down on load of the page.
Sample Jsp page
sample Action class
sample UserRegistrationActionform
I see the following error when the page is loaded
java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
java.util.ArrayList.RangeCheck(Unknown Source)
java.util.ArrayList.get(Unknown Source)
It seems your indexoutofbound exception is coming due to the declaration of your index=1. Make it index=0 and it will run fine. If this part is running fine we can move forward with populating issue.
What version of Struts are you actually using? Your subject says "<s:select>", which is Struts 2, while all your code implies Struts 1.
I'm a bit confused on some of your code:Note that I've gone ahead and made the code readable--it's nice to take care when posting and make sure that it has posted the way you expect it to.
Why do you create empty array lists then immediately assign new values? There's no reason to create the list if you just overwrite the value a line or two later.
If your array is of size 1 then there is no element at index 1--Java indexes arrays and lists starting with index 0.
The appendList() method is creating a list of ActionForms--this is almost *certainly* not what you want, unless I'm completely misunderstanding the code--in which case the code should probably be cleaned up to better express its intent.
Your stack traces would be more valuable if (a) they were complete, and (b) you were compiling with debug information so it would include the line number of where the exception took place--pointing to the middle of Java code doesn't help us determine where *your* code is at fault.
Your JSP fragment involves a "stateList" while your Java fragment shows a "countryList"--this is an additional layer of confusion. Please narrow down the problem to one or the other and post the current code, properly escaped, with more useful error information.s