Java 如何在div中执行或加载servlet?

Java 如何在div中执行或加载servlet?,java,html,jsp,servlets,Java,Html,Jsp,Servlets,嗨,我正试图在 有谁能帮我在div中加载sevlet吗?您可以在这里使用ajax在鼠标输入时从servlet加载数据。 在mouseenter函数中,您可以编写以下代码: $.ajax( { url:'showcart.jsp,'//Or whatever name is type:'get', success:function(response) { $('.testtmpblock').html(response); } }); 它将把servlet的ht

嗨,我正试图在


有谁能帮我在div中加载sevlet吗?

您可以在这里使用ajax在鼠标输入时从servlet加载数据。
mouseenter
函数中,您可以编写以下代码:

$.ajax(
{
  url:'showcart.jsp,'//Or whatever name is 
  type:'get',
  success:function(response)
  {
     $('.testtmpblock').html(response);
  }
});

它将把servlet的html呈现代码加载到div中。

不包括JSP,而是对servlet进行ajax调用以获取数据并在div-It-self中显示

$("button").click(function(){   //replace this with your event
  $.ajax({url:"showcart",success:function(result){
    $("#testtmpblock").html(result);
  }});
});

在mouseenter中,函数的意思是
$(document).on('mouseenter','.cart',函数(){
在这里?我试过了,但在
url:'showcart.jsp',
行显示了一个错误。你能确切地告诉我这个地方吗?@Aniket:太棒了..问题解决了。我用确切的代码试过了,但仍然没有显示数据。我还按下了按钮
。请分享你的Servlet代码。当ajax请求进来时您的servlet应该返回数据。我更喜欢JSON格式,需要在上面的jquery脚本中进行解析。我上面发布的内容更像是一种语法。好的,先生,但上面的答案给了我解决方案。它的工作非常艰巨,而且非常动态。
$("button").click(function(){   //replace this with your event
  $.ajax({url:"showcart",success:function(result){
    $("#testtmpblock").html(result);
  }});
});