• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

passing javascript array from jsp to servlet

 
Ranch Hand
Posts: 152
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how do i pass a javascript Array from a jsp to a servlet??
in my javascript script tag i have written this code
what i m trying to do is pass all the values of the list box to array and pass this array to servlet for inserting into the database.

function addVar()
{
//alert("hi");
var val=new Array();
val=document.getElementById("ListedSubjectID");
var i=val.length;
//alert(i);
for(var j=0;j<i;j++)
{
//alert(val.options[j].Value);
val.options[j].Value;
}
document.getElementById("Val1")[0].value=val;
}
where Val1 is the hidden field.
and ListedSubjectID is the list box name
and in my servlet i did something like

String values[]=request.getParameterValues("Val1");
for (String value : values)
{
System.out.println("The value is "+value);
}
String value=request.getParameter("Val1");
System.out.println("The Parameter value is "+value);

i tried both the methods but it does not print any thing.
the value of values[]=""
and value is =""
please help
 
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm guessing .jsp page is the page with the javascript, and the servlet is the page containing the server sided script to insert into the db and such.

what you COULD do is just make a comma delimited string with
all the values from the list box (is this a <select>?).

and then just use ajax to send that string to the server, and in the server get the querystring from the url and then insert those values into the db for as many values in the csv.



Now if you have used ajax, which I assume you have, you should
know what to do next, if not, let me know and I'll post a snippet.

I hope this is what you were talking about lol,

Justin Fox
[ June 13, 2008: Message edited by: Justin Fox ]
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
pravin shirke, Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extermely hard to read and many people that might be able to help you will just move along. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
 
Pravin Shirke
Ranch Hand
Posts: 152
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your code justin. but i dont know ajax so can you give me the code snippet please. thank you
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Thread hijack and cross-post removed.]
[ October 08, 2008: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have the same situation :

Please I would like to have the code snippet.

Thanks lot.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic