how to call a javascript file from a servlet?

R

Ryan Gaffuri

I would prefer not to include my javascript in my servlet. its too
messy. I am using j avascript to check for form errors(such as nulls
in fields). anyway to put my javascript in a seperate script and call
it from my servlet?
 
B

Bryce

I would prefer not to include my javascript in my servlet. its too
messy. I am using j avascript to check for form errors(such as nulls
in fields). anyway to put my javascript in a seperate script and call
it from my servlet?

What do you mean including javascript in your servlet? The javascript
code in the response?

If so, I use JSP's, and just include the file there...
 
M

Michael Borgwardt

Ryan said:
I would prefer not to include my javascript in my servlet. its too
messy. I am using j avascript to check for form errors(such as nulls
in fields). anyway to put my javascript in a seperate script and call
it from my servlet?

The output of a Servlet is a simple HTML page, so once it's delivered to
the client it has all the limitations and capabilities of one, including
the ability to refer the separate JavaScript files with the src attribute
of the script tag.
 
T

Tim Slattery

I would prefer not to include my javascript in my servlet. its too
messy. I am using javascript to check for form errors(such as nulls
in fields). anyway to put my javascript in a seperate script and call
it from my servlet?

Servlets run on the server. JavaScript runs on the client. You cannot
call a function on the client from the server.
 
C

Carl Howells

Ryan said:
I would prefer not to include my javascript in my servlet. its too
messy. I am using j avascript to check for form errors(such as nulls
in fields). anyway to put my javascript in a seperate script and call
it from my servlet?

Please tell me you're not using *only* javascript to test for form
errors... Please tell me everything is being double-checked sever-side,
too.

Never rely on client-side validation of data.
 
W

Will Hartung

Ryan Gaffuri said:
I would prefer not to include my javascript in my servlet. its too
messy. I am using j avascript to check for form errors(such as nulls
in fields). anyway to put my javascript in a seperate script and call
it from my servlet?

And rather than questioning the overall design, the answer to your question
is, Yes, you can call JavaScript from your Servlet.

Netscape/Mozilla has the Rhino JavaScript interpreter written in Java which
is actually quite nice. You can embed the interpreter into your servlets and
it will run JavaScript for you.

It will NOT, however, have access to the actual HTML form page (as that's in
the browser), but it will run JavaScript from a Servlet.

Regards,

Will Hartung
([email protected])
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top