0

<a>こんにちは、タグ ホバーでdiv を開こうとしています。これで完了です。そのdivにjspページデータをロードしたいです。しかし、問題はjspページのデータがサーブレットから来ることです。そのため、サーブレットが実行されない限り、データはjspページに来ません。

私のサーブレット名はshowcart.java. からデータを受け取るページshowcart.javaは ですvcart.jsp

試してみ<jsp:include page="vcart.jsp"></jsp:include>ましたが、ページ データが空です。したがって、サーブレットが実行され、制御とデータが に渡されるように、何らかのメカニズムが必要ですvcart.jsp

私のコード:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Reading Image</title>
    <style type="text/css">
        .testtmpblock{
            display: none;
            background-color: black;
            height: 100px;
            width: 100px;
            color: white;
        }

    </style>
    <script src="jquery.min.js" type="text/javascript"></script>
    <script>

        $(document).ready(function () {
      $(document).on('mouseenter', '.cart', function () {
          $(this).next(".testtmpblock").show();
      }).on('mouseleave', '.cart', function () {
          $(this).next(".testtmpblock").hide();
      });
  });
    </script>
</head>
<body>
    <a href="#" class="cart"> Cart </a>

    <div class="testtmpblock">
    <jsp:include page="vcart.jsp"></jsp:include>
</div>
</body>
</html>

div に sevlet をロードする方法を教えてもらえますか?

4

2 に答える 2

1

JSP を含めるのではなく、サーブレットに ajax 呼び出しを行ってデータを取得し、それ自体を div に表示します。

$("button").click(function(){   //replace this with your event
  $.ajax({url:"showcart",success:function(result){
    $("#testtmpblock").html(result);
  }});
});
于 2013-11-13T09:40:21.637 に答える
1

ここで ajax を使用して、マウス入力時にサーブレットからデータをロードできます。
関数ではmouseenter、次のコードを記述できます。

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

そのサーブレットの html レンダリング コードを div にロードします。

于 2013-11-13T09:37:24.573 に答える