ajax 调用java类_在ajax中调用java方法

AJAX是Asynchronous JavaScript And XML的首字母缩写.它提供了异步与服务器通信的能力.

要简单地解释一下,您可以向服务器发送请求并继续与用户进行用户交互.您无需等待服务器的响应.响应到达后,UI中的指定区域将自行更新并反映响应信息.整页不需要重新加载.

因此,您无法直接访问Java类作为URL来发出Ajax请求.它应该是任何映射的URL,如JSP,Servlets,PHP等.

创建JSP(例如hello.jsp)

String strResponse;

mail.Main objMain = new mail.Main();

strResponse = objMain.execute();

%>

在Ajax请求中

url: "hello.jsp",

编辑:添加示例:

$(function(){

function getData() {

var dataToBeSent = {

uName : $("#userName").val() , //

passwd: $("#password").val()

}; // you can change parameter name

$.ajax({

url : 'getDataServlet', // Your Servlet mapping or JSP(not suggested)

data :dataToBeSent,

type : 'POST',

dataType : 'html', // Returns HTML as plain text; included script tags are evaluated when inserted in the DOM.

success : function(response) {

$('#outputDiv').html(response); // create an empty div in your page with some id

},

error : function(request, textStatus, errorThrown) {

alert(errorThrown);

}

});

}

});

在Servlet / JSP中访问你的参数request.getParameter(“uName”);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值