0

I need to pass my array of dynamically created objects from jsp to java action class , Meanwhile i am tring following code to set array objects as a request parameter for action form . But while fetching in action class it produce null result ,as array object are not passed on to action form. Kindly provide me a right way to pass array list to action class. Thanks in advance ////

<script>
var i;
var arraya = new Array();
var arrayb = new Array();
var arrayc = new Array();
var idCount = 1;
function arr()
{
for (var j=0;j<idCount;j++)
{
arraya[j]=  document.getElementsByName("a"+j)[0].value;
arrayb[j]=  document.getElementsByName("b"+j)[0].value;
arrayc[j]=  document.getElementsByName("c"+j)[0].value;
}
var one=arraya.valueOf();
var two=arrayb.valueOf();
var three=arrayc.valueOf();
} 
</script>
    <input type="text" name="a0">
<input type="text" name="b0">
<input type="text" name="c0">
    <input type="button" onclick="addDiv();" value="Add"/>
<input type="hidden" name="one" value="<%= request.getParameter("one") %>" />
<input type="hidden" name="two" value="<%= request.getParameter("two") %>" />
<input type="hidden" name="three" value="<%= request.getParameter("three") %>" />

1 Answer 1

1

You can achieve it by doing this -

Simply have input type like this. Notice no index used.

<input type="text" name="a"/>
<input type="text" name="b"/>
<input type="text" name="c"/>

In your action class you can then do this. The values will be in the order.

String[] a = request.getParameterValues("a");
String[] b = request.getParameterValues("b");
String[] c = request.getParameterValues("c");

Although since you are using Struts you should actually create an object having properties a, b and c. Use the object in array fashion.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.