This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jsp & JavaScript

 
kanth varada
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Friends,

How can use the variables that are declared in the JavaScript in a Jsp Page.

Ex: I declare a variable..

var i=1;
i=i+1;

and i want to use the value of i in ordinary jsp page..

Pls give me suggesions how can i approach that kind of stuff.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think that you can.
I mean, JSP is interpreted server side.
 
lakshmi v.samy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,

In similar way I have declared one variable in jsp,
<% int i=0; %>
can i use this variable in my javascript?

Please help me.

Thanks in advance.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In similar way, <% int i=0; %> is interpreted server side, so not accessible from javascript.
 
lakshmi v.samy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
Vinny Menon
Ranch Hand
Posts: 62
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi lakshmi
Probably you could have a hidden variable in the jsp which stores the value of the jsp scriptlet.

and then use the value as shown below


hth
cheers
Vinny m
 
kanth varada
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we use sessions in javascript.

if yes pls send me the syntax...

i want to use the Javascript variable value in jsp,how can i do that.Pls help me frineds.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinny,

If lakshmi meant outputting the value of i to use it in javascript (which is different from accessing a variable),
he could simply use in a Javascript function:
int i = <%= i %>;

instead of using hidden tags.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kanth,

can you explain what you are trying to do ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might find this article instructive on this issue.
 
Vinny Menon
Ranch Hand
Posts: 62
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Satou,
you are right...
Thanks for your correction.
cheers
vinny m
 
kanth varada
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what exactly i meen to say is...

we r using some custom tags in our jsp page there is one tag which display the description.so i want to store the entire discription in the variable.

because i am checking some condition to display the description.the description must display when it enter the loop.that entire looping stuf was in javascript.so what i want to do is when it enter the loop i just want to make the variable value to '1' other wise '0' and i want to check that in ordinary jsp page to diplay the discription.So pls help me in this stuff........
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the article.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And kanth, JavaRanch is a community of people from all over the world, many of who are not native English speakers. While using abbreviations like "r" instead of spelling out "are" is convenient when text messaging your friends on a cell phone or in a chat room, it presents an extra challenge to those that are already struggling with English. Additionally, such shortcuts may confound automated translation tools that patrons of the Ranch may be making use of.

I would like to ask for your help in making the content of JavaRanch a little easier to read for everybody that visits here by not using such abbreviations.

Please read this for more information.

thanks,
bear
JavaRanch Sheriff
[ February 15, 2006: Message edited by: Bear Bibeault ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic