"Tonight on 'It's the Mind', we examine the phenomenon of Deja Vu . . ."

Again, Java and JavaScript live in different worlds. Not only that, but when
the Java in the JSP is executed, the JavaScript doesn't even exist. So
getting JavaScript data and variables into the Java just isn't possible,
period.

So for your first example, you can certainly use the URL of a JSP there (I'm
assuming that assigning to window.location causes the browser to go to that
URL). In order for the invoked JSP to "see" your JavaScript variable, you
would have to pass it as a parameter to the JSP, which means that the
variable must be a simple string (or resolve to a meaningful string). For
example, you could certainly do this:

function(file_obj) {
  Window.location="MyFile.jsp?fileparm=" + file_obj;
}

if the "file_obj" thing is a file NAME rather than a full-blown object that
you want your JSP to be able to deal with directly. This works because it's
all in the JavaScript space, it's just invoking a URL that happens to be a
JSP (and constructing the URL using a JavaScript variable).

On the other hand, if file_obj is a JavaScript object, and you want the
invoked JSP to have access to the object itself, I don't think you can do
that. JavaScript objects are in a completely different space (i.e. on the
browser) than Java (i.e. on the server) and I know of no way to pass an
object from the former into the latter.

Your second example will just not work. The JSP scriptlet:

<% cb.setFile(file_obj); %>

Is executed on the server at page request time. The "file_obj" variable is
in JavaScript, which doesn't even exist at that time. At page request time,
the JavaScript is just a bunch of character data that the JSP is going to
send to the browser. Only when it gets to the browser does it become a
JavaScript program.

You last example lives entirely in the JSP world. To pass objects (like
Files) between JSPs, you need to store the object in the session scope so
that the other JSP can retrieve it. Get a good book on JSP and read about
session scope.

--Jim Preston


-----Original Message-----
From: A mailing list about Java Server Pages specification and reference
[mailto:[EMAIL PROTECTED]]On Behalf Of Tom Yang
Sent: Friday, August 04, 2000 11:30 AM
To: [EMAIL PROTECTED]
Subject: How can I pass an argument from a JacaScript function to a Jsp
file?


Hi all:
  Can anyone please tell me that how I can invoke a Jsp file within the body
of a JavaScript function AND pass an argument to the Jsp file? such as

function(file_obj) {
  Window.location="MyFile.jsp";
}

I would like the MyFile.jsp to see the variable file_obj, and use it. But I
don't know how to make this happen.

Actually, I have two other related questions
Firstly, can I execute a Jsp statement within the body of a JavaScript
function? such as

function(file_obj) {
  <% cb.setFile(file_obj); %>
}

I tried it. The compiler doesn't like it. Is there a way to do it? I really
need that functionality in my programming.

Secondly, oftentimes I need to invoke a Jsp page and pass an argument to it,
such as in the following HTML statement

<A HREF="MyFile.jsp">Click Me</A>
When I invoke that MyFile.jsp, I would like it to have an argument file_obj,
which is a Jsp variable <% File file_obj; %> defined and initialized earlier
in the same Jsp page.
  Your help is appreciated. Thanks!

Tom




________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
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".
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