• 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
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

How to pass java script variable to JSP?

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can i pass Java script variable to JSP?
I have a code like this...
<script type="text/javascript">
var editArray = {50,60,70,80};
</script>

Note editArray is an array.
Now i want to pass this to my JSP.
How do i pass this as an hidden field?

<input type="hidden" value="???"
id="sample" />


Also, how to get this hidden field in my controller? because editArray is an array?

please help me out.
 
author & internet detective
Posts: 42271
951
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mean how to submit the variable's value in a forum so the JSP can read it. (JSPs can't read JavaScript variables.)

You have two choices:
1) Put a string representing the array in the hidden field. (such as a comma separated value format).. If you go this route, you call request.getParameter() and parse it in Java.
2) Store each value of the array in a field like we do with multi select fields. If you go this route, you call request.getParameterValues().
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic