Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

calling a servlet from javascript function??

 
deep venu
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can i call a servlet from inside a javascript function??
 
Vels Manian
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic