• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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.
 
I was her plaything! And so was this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic