• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic