Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Pass Javscript array from jsp to servlet  RSS feed

 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi i have got javascript inside jsp which conatins an array i need to pass the array from jsp to servlet i tried this way
[code]

<script>

for(c=0;c<1108;c++)
{
var plotnumber=var plotnumber=mygrid2.cells(rowidarray[c],0).getValue();

areacodearray[c]=plotnumber.replace(/^\s+|\s+$/g, '');
}

<%
request.setParameter("csvstring",areacodearray);
%>
document.getElementById('if1').src = "Upload?count="+rowidarray.length+"&dbenvi="+dbenvi+"&finaldate="+finaldate;
FAForm1.reset();
</script>





[code]

but this is not working any suggections please.
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't pass JavaScript array to JavaServlet instance.
I don't the requirements of your application but you can pass it via Ajax.
 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can i pass it via ajax can you give me an example


is this the way can you please suggest me
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does "passing from JSP to servlet" mean? Does the JSP embed JavaScript code in the HTML, which should then transfer some values to a servlet via AJAX or as part of an URL?
 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes jsp contains javascript and i need to pass the array present in javascript to the servlet,
Initailly i read my form values and made a comma separated string out of it and tried passing to servlet , this could call servlet only when the string passed is of short length if the string is containing 1000 comma separated string values the url is not properly formed.

if i pass the value as part of url the servlet is not getting called because the url is properly formed.

therefore i made an array of all the form values and i want to pass it to the servlet can you please suggest me ....
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you have form values as well as JavaScript variables that you want to submit? In that case you can add hidden fields to the form for all the JavaScript values (using JavaScript), and then submit the form.
 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would explain the complete issue ,here i need to pass a string conatining 20000 to 50000 charactars as parameter to servlet , this servlet i am calling from a javascript as source to iframe, to achieve this 1) first i created a csv of all the string but as the string contains very large number of charactars the url was not properly getting created and the servlet wasnot getting called so i tried using a 2)hidden field next i put the 20000 to 50000 charactar string in hidden field and tried calling the servlet using httpclient , i have got several buttons with the form attached and i want to fire the httpclient post method on click of a button where the parameter i am pasing is the hidden field value.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!