javascript 从javascript调用jsp方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11401674/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
call a jsp method from javascript
提问by Dineshkani
I use a method in jsp page like this and the page is saved in the name of new.jsp
我在这样的jsp页面中使用了一个方法,该页面以new.jsp的名称保存
<%!
public void createXml(String graph) throws Exception
{
try
{
String str="dinesh"
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
}
catch(Exception e)
{
System.out.println(e);
}
}
%>
If i call this page like this
如果我这样称呼这个页面
<form method="post" action="new.jsp">
But, I want to call this method of createXml only using javascript or jquery coding because i am going add various method in the new.jsp. Any one help this to call method without calling the whole jsp page
但是,我想只使用 javascript 或 jquery 编码来调用 createXml 的这个方法,因为我要在 new.jsp 中添加各种方法。任何人都帮助这个调用方法而不调用整个jsp页面
采纳答案by bokonic
What you're looking for is how to create an ajax request. You can do it without jqueryor easily with jQuery:
您正在寻找的是如何创建 ajax 请求。您可以不使用 jquery或使用 jQuery 轻松完成此操作:
$.post('new.jsp',{ param1: 'param1value', param2: 'param2value'},function(data){
if(data){
console.log(data); // response from your server
}
});
There's a lot more info in the jQuery docs
jQuery 文档中有更多信息
回答by zod
this will help you to do combination of ajax jquery jsp
这将帮助您组合 ajax jquery jsp
http://www.cs.wcupa.edu/~rkline/Java/ajax.html
http://www.cs.wcupa.edu/~rkline/Java/ajax.html
have a look
看一看
check AJAX HTML data transmission
检查 AJAX HTML 数据传输
$(function() {
$("#button").click(function() {
$.ajax({
type: "GET",
url: "handler/book_table.jsp",
data: { id: $("#sel").val() },
success: function(data) {
$("#out").html( data )
}
})
})
})
回答by Dineshkani
Here use this
这里用这个
$.post("new.jsp", { name: "John", time: "2pm" },
function(data){
alert("Data Loaded: " + data);});