aspose file tools*
The moose likes JSP and the fly likes How to use variables in a javascript from the same JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to use variables in a javascript from the same JSP" Watch "How to use variables in a javascript from the same JSP" New topic
Author

How to use variables in a javascript from the same JSP

Jibesh Patra
Greenhorn

Joined: Mar 19, 2008
Posts: 5
I have got a JSP . On the top of the page I have got a javascript code. Now a variable is declared in the Javascript code, I want to use that variable in my JSP.
How do I do that please help !!!
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

What's important to understand is that Javascript is interpreted on a different machine than your JSP code, at a different time.
Since Javascript is the result of your JSP's execution, it can only be interpreted (in the browser) after the JSP execution has finished.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

Please read this article to understand how JSP works.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Prafulla N. Patil
Ranch Hand

Joined: Mar 20, 2006
Posts: 106
temporary workaround for this can be as follows

you can try putting textbox in your jsp and then set the value of the variable to that textbox and then you can access that value once jsp is processed.

but thats true that you can access javascript variable directly in the same JSP


Thanks, Prafulla Patil
SCJP, SCWCD
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Prafulla N. Patil:
temporary workaround for this can be as follows


There really isn't a workaround for not understanding this fundamental web programming concept. I think the original poster will do much better if (s)he stops and takes the time to understand this. Handing him/her a workaround or patch that gets something working without the need for this understanding will hurt more than help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use variables in a javascript from the same JSP