zero said:
the easiest way to see the difference is one simple sentence: JSP runs on
the server, JavaScript runs on the client.
As a result, JSP is more used to change the *contents* of a webpage, and
JavaScript for the *presentation*. It is quite common to use both on the
same page.
Furthermore, JSP uses Sun's Java technology. Despite the name, JavaScript
has little to do with Java - the syntax just looks a little alike, but
then
so does C++
To elaborate on zero's responce, both technologies are typically used in
an web environment, with the client using a web browser to interact with a
web application hosted by a server. The server will run the JSP code, and
will typically emit HTML code. Within that HTML code, there may be some
JavaScript code embedded within it.
The client will never see the JSP code, and has no control over it. All
the client receives is the HTML code (with optionally some JavaScript
embedded in it). The browser may then run the JavaScript code. Or perhaps
the user may have JavaScript disabled on their browser, in which case the
JavaScript code will not run at all.
Because of this, it is unwise to put "critical behaviour" in JavaScript,
as it might not get executed. However, the advantage of JavaScript is that
it is running locally on the client, so no round trip (e.g. connection to
HTTP server, sending request, receive reply, closing connection) is
required.
Google Maps uses JavaScript where possible to allow for the map to be
scrolled around; but when the user enters an area for which the satelitte
imaging has not yet been downloaded, the JavaScript initiates a connection
to the server to download more content.
Without JavaScript, every movement by even a single pixel would require
a round trip, thus creating "unbearable" lag for the user.
JavaScript was given this name purely for marketing reasons. Developped
by Netscape, the technology was originally called LiveScript. Then, when
Netscape partnered with Sun to promote the concept of "Applets embedded in
web pages", the LiveScript language was renamed to JavaScript (thus creating
endless confusion on these newsgroups about the distinction between
JavaScript and Java). "JavaScript" technically is a collection of languages,
as each browser implements its JavaScript interpreter slightly differently.
Microsoft's Internet Explorer, for example, had something called "JScript"
and it is not certain whether this should be considered a "flavour of
JavaScript", or a different (but similar) technology to JavaScript.
"ECMAScript" is one particular flavour of JavaScript standardized by the
ECMA. Some people will use the terms "LiveScript", "JavaScript", "JScript"
and "ECMAScript" interchangeably.
Also, JSP is normally compiled to bytecode, and the bytecode is run on
the server, whereas JavaScript is normally interpreted, where the JavaScript
sourcecode itself is presented to the interpreter (usually embedded within a
web browser) and no extra compilation step is nescessary.
Here's "Hello World" in JavaScript:
document.write('Hello, world!');
Here's "Hello World" in JavaScript embedded in HTML:
<html><body><a href="#" onclick="alert('Hello, world!'); return
false;">Hello World Example
</a></body></html>
Here's "Hello World" in JSP:
<html><body><%="Hello World!" %></body></html>
- Oliver