• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Assign Javascript value to JSP var

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Thanks a lot in advance.
I have some value in javascript and I want to assign that value to a jsp variable.
I know how to assign a JSp value to a javascript variable but I am not getting any idea on this.

I have a code like below
<Script language='javascript'>
var x=5;
</script>
And I want to set this x value in seesion attribute,like
<%
session.setAttribute("XJavascript",x)---this should be javascript value
%>

Regards,
Sree
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is not any direct way to apply javascript value into JSP, because javascirpt run on client side and the JSP is server side language.

the only way I know is by using a hidden fields,
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This wont compile as x is not defined, Here x should be a java variable( not java script) of type Object.

What exactly are you trying to do, give the scenario, maybe there is some another way of doing it.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Saif has mentioned, the only way to achieve this as per my knowledge is to use hidden fields along with your form. For e.g.



then in your javascript set the value as:



This should work.
 
You can't expect to wield supreme executive power just because
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic