从javascript调用jsp方法 [英] call a jsp method from javascript
本文介绍了从javascript调用jsp方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在jsp页面中使用这样的方法,页面以new.jsp的名义保存
I use a method in jsp page like this and the page is saved in the name of 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">
但是,我想只使用javascript或jquery编码来调用createXml的这个方法,因为我要添加new.jsp中的各种方法。任何人都可以在不调用整个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
推荐答案
您正在寻找的是如何创建ajax请求。您可以不使用jquery 或使用jQuery轻松实现:
What you're looking for is how to create an ajax request. You can do it without jquery or easily with jQuery:
$.post('new.jsp',{ param1: 'param1value', param2: 'param2value'},function(data){
if(data){
console.log(data); // response from your server
}
});
这篇关于从javascript调用jsp方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文