You can not access JSP variables directly using javascript because of the
most basic difference between the two.  JSP is a server-side scripting
language.  The JSP engine builds source code for a servlet from the JSP
page, the servlet is executed and html is sent to the browser.  Whereas,
javascript is a scripting language that the client's browser interprets and
executes.  Thus, it is not possible to DIRECTLY access JSP variables.
However, you can use JSP to place String variables within javascript so that
the javscript can be created dynamically.

For example, the following code:

        <% String some_jsp_var = "This is a java variable instantiated in a
JSP."; %>

        <script language="Javascript">
        function callMessage(){
                alert("<%=some_jsp_var%>");
        }
        </script>

would produce the following html to be received by the client:

        <script language="JavaScript">
        function callMessage(){
                alert("This is a java variable instantiated in a JSP.");
        }
        </script>

In short Ganesh, you can use the values of JSP String variables within
javascript, however remember that there is no way to change the value of JSP
variables from javascript because of the environments that each language
runs on.

Joseph Karau
Kingland Systems
[EMAIL PROTECTED]
507-536-3629


-----Original Message-----
From: Ganesh Mohan Rao [mailto:[EMAIL PROTECTED]]
Sent: Friday, December 01, 2000 3:20 PM
To: [EMAIL PROTECTED]
Subject: How to access JSP variable from javascript?


Please tell me Gurus.

How to access JSP variable from javascript?

Ganesh.

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to