Not directly. JavaScript executes on the client after the servlet or JSP has sent the HTML page to the browser. You can use Ajax to issue another request to a servlet under script control.
Yes it is possible to call a servlet using javascript(JSP).
one example is using the <form> tag...
here is a sample...
<form method ="get" action="myservlet">
<input type="submit" name="aaaa" value="zzz">
</form>
In this sample, your javascript would call a servlet with a filename myservlet.java upon clicking the button. Take note that you need not put the extension name of the servlet if a javascript would call it.
If I stare at something, it doesn't necessarily mean that it is beautiful..... because most of the time, I stare to see how ugly it truly is....
Sorry I didn't make myself clear.... if you want to call the add() function, then just create a seperate servlet which would contain all the methods in your add() function and call the newly created servlet... then would be as if you called the add() itself.... well just trying to help...
If I stare at something, it doesn't necessarily mean that it is beautiful..... because most of the time, I stare to see how ugly it truly is....
The AJAX recommendation was a good suggestion. It's what we use. Here is a little portion of code were we call a servlet (CreateProgramCopy) from a JSP page using javascript. One thing to notice, that in this example is that we call this servlet "synchronously" which means the javascript code waits for the servlet to finish before moving on. In this implementation we found that if we made an asynchronous call we ended up having too many open connections because this code is called many times if a user selects multiple records to copy. For example of they select 20 records to copy, this code will run 20 times and we end up with 20 connections to our server and that was too much. The user has to wait a brief period before this completes but that was acceptable.