开发者

calling Servlet post method using javascript

i need to call servlet post method using javascript ,i have done like this

 var iframe= document.getElementById("开发者_如何学Goiframe");
 iframe.src = "MyServlet";


You have done it incorrectly.

You need to set the src to a URL that will invoke the servlet, such as

iframe.src = "/Path/To/Something";

If you want to send a POST request, you'll need to create a <form action="/Path/To/Something" target="IFrameName"> and call submit().


Note that it is more efficient to use AJAX, with an XMLHttpRequest. The easiest way to do that is with jQuery:

$.get("/Path/To/Something");

(Although you would want to call $.post)


There are two ways to POST to a server:

  • submit a <form> with method="POST"
  • use ajax and specify POST as method

All other options are invoking GET

That said, MyServlet is unlikely to be a valid path. You need to specify the path that you configured as <url-pattern> in web.xml

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜