Click to See Complete Forum and Search --> : call a servlet with javascript


jean-baptiste
03-08-2003, 04:44 PM
Hi,
How to make to call a servlet java with Javascript with parameters.
For the moment, I call the servlet by submit a form HTML
For example:

function submit(){
document.endSession.submit();
}
with this form:
<form name="endSession" METHOD="POST" ACTION="./securite.SessionLogOut">
<input type="hidden" name ="user" value="noel"/>
</form>

But I would like to find a means of calling it without passing by a form HTML, because I often make this same call in several page HTML.
Thank you

khalidali63
03-08-2003, 04:53 PM
you can not do it that way,you have to use either the locationbar of the browser for the address of the servlet or the action attribute of the form.it would be really surprising if you were able to do it otherwise,As you would already know the servlet responses to HTTP protocols Get and POST methods only.

Cheers

Khalid

jean-baptiste
03-10-2003, 03:03 PM
You are right, but one can circumvent the problem with the DOM.
For example:
var myBody=document.getElementsByTagName("body") myForm = document.createElement("FORM");
myForm.setAttribute("action","log.html");
myForm.setAttribute("method","post");
myBody.appendChild(myForm);

//Here, you can set parameters with adding button element
myForm.submit();

do very well work.