aspose file tools*
The moose likes JSP and the fly likes Javascript variable inside jsp scriplet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Javascript variable inside jsp scriplet" Watch "Javascript variable inside jsp scriplet" New topic
Author

Javascript variable inside jsp scriplet

Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
Hi,

is there any way to pass a javascript variable value to a variable inside a scriplet in a JSP. ( this needs to be achieved without submitting the form)

Thanks,
Neeraj
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

I don't think it's possible. You can pass JSP value to javascript, but not the other way around.


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

One thing that needs to be understood is that Javascript and your JSP scriptlets are interpreted at different times, on different machines.

The scriptlet is interpreted on the server. It's output is the HTML and javascript that goes to the browser.
The HTML is rendered, and the Javascript is interpreted in the client (browser). The scriptlet code never goes to the browser and it has already finished being interpreted at this point.


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: 60053
    
  65

Originally posted by Freddy Wong:
You can pass JSP value to javascript,


No, you can't. What you can do is to use the value of JSP variables to create JavaScript that contains these values. But you can't "pass" anything.

Please read this article to understand why there can be no "passing" in either direction.
[ July 31, 2007: Message edited by: Bear Bibeault ]

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

Joined: Mar 20, 2006
Posts: 106



in process.jsp you can get value of "javascriptvar"

getting value in that page itself is not possible


Thanks, Prafulla Patil
SCJP, SCWCD
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

Submitting a value to another JSP is not what the original poster was asking about.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javascript variable inside jsp scriplet
 
Similar Threads
Accessing Scriplets Value Inside Javascirpt
can we use java object in java script
get URL of browser in Scriplet
pass Sciptlet to jsp
check File Existence and display alert message