wood burning stoves 2.0*
The moose likes Servlets and the fly likes calling a servlet from javascript function?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "calling a servlet from javascript function??" Watch "calling a servlet from javascript function??" New topic
Author

calling a servlet from javascript function??

deep venu
Ranch Hand

Joined: Jun 09, 2001
Posts: 56
how can i call a servlet from inside a javascript function??
Vels Manian
Greenhorn

Joined: Jun 28, 2001
Posts: 22
You can very well call a servlet from a javascript function.
document.location.href=/ServletName?param1=value1&param2=value2..
This line of code causes the servlet to be called using get method.
If the servlet needs to invoked using post method
You can set the forms action to the servlet to be called and method to POST and in the javascript function just you can say
document.<formname>.submit();
I hope this helps
Regards
Vels
[This message has been edited by Vels Manian (edited July 01, 2001).]
deep venu
Ranch Hand

Joined: Jun 09, 2001
Posts: 56
Hi Vels,
thanx..
i was aware of the submit function ..what i actually was trying out was that i need to pop up a window on a particular value getting selected from a list box..
I used to do this using window.open property..can i pass the URL of a servlet instead of a normal html page ??
Vels Manian
Greenhorn

Joined: Jun 28, 2001
Posts: 22
Hi,
Ofcourse, u can pass a URL of a servlet in the window.open().
If u want to call the servlet using POST method. U can set the target of the form to the window name and submit the form.
For ex:
<SCRIPT>
function onClickSubmit()
{
window.open("mywindow");
document.<frmname>.submit();
}
</script>
<body>
<form name="frmmain" action="/Servlet" target="mywindow" method="POST">
..
</form>
</body>
</html>
Try this out.
Vels
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: calling a servlet from javascript function??
 
Similar Threads
Servlet with Javascript
Calling a Servlet (Urgent)
calling javascript function
JOptionPane No X11 DISPLAY error
Calling .js file from Java