sorry, i don't quite get what you are saying?
if its in you JSP you could do:
request.setParameter("serverSideArrRef", myArrayName);
This will add a parameter serverSideArrRef in this case to the request object of the JSP. If the JSP contains a form or something like that and if you submit this form, then the parameter goes thru the request and you can access it {on the server side?} in your servlet/beans etc...
Not sure if this is what you were looking for or not...
- madhav
> sorry, i don't quite get what you are saying?
I'm not getting it either. If your trying to submit multiple from elements with the same name to a server you can get those values by using String[] vals = request.getParameterValues(param_name);
> request.setParameter("serverSideArrRef",
> myArrayName);
>
this is actually request.setAttribute incase you try using this and find it wont work.
Hi! am sorry .. i just cant construct the right words to explain what i mean clearly ... well, i've got this code in my JSP page and I have a form, the problem is how can I submit the array and their element to the server. Can I use dynamic hidden textboxes? document.<formname>.writeln wont work in creating the hidden text box so that i can include the array in submitting the form. Hope u all can picture out what am trying to do ... THANKS A LOT people!!!
<SCRIPT>
function onSubmit(val, funcid, userid,userval){
var len1, len2;
var elementvalue, elementname;
len1 = cntctid1_add.length;
len2 = cntctid2_add.length;
for(var ctr1 = 0; ctr1 < len1; ctr1++){
elementvalue = cntctid1_add[ctr1];
}
I'm not sure if this is the answer you're looking for, but when I made a preferences page I put all the values in an array and then serialized it to a hidden input.
something like:
<input type=hidden name=array value="<%=writeObject(array)%>"/>
I don't know if that will help you and it's not the most practical solution to whatever you might be doing.
Ok, I think I see what you want to do. You have a jsp page that once at the browser creates an array in javascript, or something to that affect. The array you are talking about is on the client end, not the server.
So to give an example of what I think you mean, say you have a text box and a button in an html page. You can type some text in the text field and then click the button to do some javascript to add this value to a javascript array. Once done adding all of the desired items you want to send that array of information to a server side proccess to do something with that array.
If this is the kind of case you are talking about then one way to do this would be to have one hidden text field on the page that will be a place holder for the values to be submitted. Then upon submition have a javascript function cycle through all of the values and create some kind of delimited string to pass to the server. Your servlet could then use a StringTokenizer to parse the string for all of the values that it contains.
I just answered a similar question in this thread: http://forum.java.sun.com/thread.jsp?forum=45&thread=195172
What you have to understand is that Javascript can not talk directly to JSP because they are running on two separate platforms. The best way to go about doing what you're attempting is to build the array from JSP session variables. This will maintain persistence of array values between requests. Think of it like this. Everytime the page is requested your JSP code should write each of the array values from info currently stored in the session object. If there is a need to change any values of the array elements you should include some sort trigger to send a new request from the browser containing parameters for the updated array elements. Take the example found at the above link. If you wanted to update say the second array element to a value of seven as a result of the end user clicking on an image for example, then you could code an <A> tag with request parameters that would trigger the change on the JSP side. See the following:
<a href=<%="\"" + request.encodeURL("thispage.jsp?elem=2&val=7") + "\""%>
> <img src="goofy.jpg"> </a>
Then somewhere after creating the array in JSP but before storing it in the request object you could read in these parameters via request.getParameter() and make the change to the jspArray.
I apologize for spliting my idea across multiple threads but you'll get the point if you read the other thread.
Regards,
Cliff