91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

JavaScript中如何實現調用Java方法

發布時間:2020-11-03 15:52:15 來源:億速云 閱讀:139 作者:Leah 欄目:開發技術

JavaScript中如何實現調用Java方法?針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

HTML代碼

<table id="cartTable">
  <thead>
    <tr>
      <th class="product_remove">
        <label>
          <input class="check-all check" type="checkbox"/>  全選
        </label>
        <a class="fl delete" id="deleteAll" href="javascript:;" rel="external nofollow" ><i class="fa fa-trash-o"></i></a>
      </th>
      <th class="product_thumb">圖片</th>
      <th class="product_name">名稱</th>
      <th class="product-price">價格</th>
       <th class="product_quantity">款式</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td class="product_remove">
        <input class="check-one check" type="checkbox"/>
      </td>
      <td class="product_thumb">
        <a href="ShopShoesDetails.jsp&#63;shoes_id=<%=shoes.getShoes_id() %>" rel="external nofollow" rel="external nofollow" >
          <img src="${pageContext.request.contextPath}/ShopServlet&#63;method=getShopsShoesImage&shoes_id=<%=shoes.getShoes_id() %>" alt="">
        </a>
      </td>
      <td class="product_name">
        <a href="ShopShoesDetails.jsp&#63;shoes_id=<%=shoes.getShoes_id() %>" rel="external nofollow" rel="external nofollow" ><%=shoes.getBrand() %>/<%=shoes.getSeries() %>/<%=shoes.getName() %>
        </a>
      </td>
      <td class="product-price"><%=shoes.getPrice() %></td>
      <td class="product_quantity"><%=shoes.getSex() %>/<%=shoes.getSize() %></td>
    </tr>
  </tbody>
</table>

ShopShoesDao.java

public void deleteFromCart(String shoes_id) {
    System.out.println("ShopShoesDao.deleteFromCart");
    String[] shoes_ids = shoes_id.split(",");
    
    Connection connection = DBUtil.getConnection();
    PreparedStatement preparedStatement = null;
    
    try {
      for (String string : shoes_ids) {
        int id = Integer.parseInt(string);
        String sql = "delete from user_product_cart where shoes_id = &#63;";
        preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setInt(1, id);
        preparedStatement.executeUpdate();
      }
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }finally {
      DBUtil.close(preparedStatement);
      DBUtil.close(connection);
    }
  }

ShopServlet.java

protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    System.out.println("service");
    request.setCharacterEncoding("UTF-8");
    String method=request.getParameter("method");
    System.out.println(method);
    if(method.equals("addProduct")) {
      addProduct(request,response);
    }else if(method.equals("getShopsShoesImage")) {
      try {
        getShopsShoesImage(request,response);
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }else if(method.equals("addToCart")) {
      try {
        addToCart(request, response);
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }else if(method.equals("deleteFromCart")) {
      try {
        deleteFromCart(request, response);
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }else if(method.equals("payFromCart")) {
      try {
        payFromCart(request, response);
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
private void deleteFromCart(HttpServletRequest request, HttpServletResponse response) throws IOException, SQLException {
    // TODO Auto-generated method stub
    System.out.println("deleteFromCart");
    request.setCharacterEncoding("UTF-8");
    int user_id= Integer.parseInt(request.getParameter("user_id"));
    System.out.println(user_id);
    String shoes_id = request.getParameter("shoes_id");
    System.out.println(shoes_id);
    ShopShoesDao shopShoesDao = new ShopShoesDao();
    shopShoesDao.deleteFromCart(shoes_id);
    request.getSession().setAttribute("shoes_id", shoes_id);
    response.sendRedirect(request.getContextPath()+"/cart.jsp");
  }

javascrip代碼

// 點擊全部刪除
  deleteAll.onclick = function () {
    if (selectedTotal.innerHTML != 0) {
      var con = confirm('確定刪除所選商品嗎?'); //彈出確認框
      if (con) {
        var shoes_id = '';
        for (var i = 0; i < tr.length; i++) {
          // 如果被選中,就刪除相應的行
          if (tr[i].getElementsByTagName('input')[0].checked) {
            shoes_id = shoes_id + tr[i].cells[0].innerHTML + ',';
            
            //tr[i].parentNode.removeChild(tr[i]); // 刪除相應節點
            //i--; //回退下標位置
          }
        }
        alert(shoes_id);
        window.location.href="ShopServlet&#63;method=deleteFromCart&shoes_id=" rel="external nofollow" +shoes_id+"&user_id="+22;
        alert("刪除成功!");
      }
    } else {
      alert('請選擇商品!');
    }
    getTotal(); //更新總數
  }

關于JavaScript中如何實現調用Java方法問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注億速云行業資訊頻道了解更多相關知識。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

莎车县| 会昌县| 中超| 新乡县| 雷州市| 织金县| 伊宁县| 松潘县| 宝鸡市| 衡阳市| 卢龙县| 长宁县| 龙海市| 江口县| 横峰县| 乐都县| 西峡县| 安康市| 滨州市| 兴文县| 庆城县| SHOW| 瑞安市| 龙陵县| 夏河县| 额济纳旗| 游戏| 南通市| 民权县| 孟津县| 靖西县| 新宁县| 赣州市| 万年县| 西青区| 巨鹿县| 河北区| 淳化县| 恩施市| 大厂| 沙洋县|