File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Jsp & JavaScript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Jsp & JavaScript" Watch "Jsp & JavaScript" New topic
Author

Jsp & JavaScript

kanth varada
Greenhorn

Joined: Feb 14, 2006
Posts: 14
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

I don't think that you can.
I mean, JSP is interpreted server side.


[My Blog]
All roads lead to JavaRanch
lakshmi v.samy
Ranch Hand

Joined: Feb 02, 2006
Posts: 30
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

In similar way, <% int i=0; %> is interpreted server side, so not accessible from javascript.
lakshmi v.samy
Ranch Hand

Joined: Feb 02, 2006
Posts: 30
thanks
Vinny Menon
Ranch Hand

Joined: Jan 10, 2006
Posts: 62

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


Regards,Vinny M.
proud Fan of European Champion CHELSEA FC
"If you don't see the bug where you're looking, perhaps you're looking in the wrong place" -James Gosling
kanth varada
Greenhorn

Joined: Feb 14, 2006
Posts: 14
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Nov 24, 2005
Posts: 14687
    
  16

kanth,

can you explain what you are trying to do ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

You might find this article instructive on this issue.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vinny Menon
Ranch Hand

Joined: Jan 10, 2006
Posts: 62

Hi Satou,
you are right...
Thanks for your correction.
cheers
vinny m
kanth varada
Greenhorn

Joined: Feb 14, 2006
Posts: 14
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

Joined: Jan 10, 2002
Posts: 60800
    
  65

Read the article.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

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 ]
 
Consider Paul's rocket mass heater.
 
subject: Jsp & JavaScript
 
Similar Threads
jsp and javascript
calling functions in .js file
md5 jsp javascript
Hidden fields in Javascript
Disabling a submit button.