Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Assign Javascript value to JSP var

 
sridhar lakka
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • 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
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • 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,
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • 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.
 
Krithika Srinath
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic