国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

JavaScript中如何調用Java方法

瀏覽:64日期:2023-10-13 14:07:40

在JavaScript中想要調用Java的方法,我通過JavaScript訪問servlet,再通過servlet調用Java某個類的方法。

HTML代碼

<table id='cartTable'> <thead> <tr> <th class='product_remove'><label> <input type='checkbox'/> 全選</label><a 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 type='checkbox'/> </td> <td class='product_thumb'><a href='http://m.cgvv.com.cn/bcjs/ShopShoesDetails.jsp?shoes_id=<%=shoes.getShoes_id() %>' rel='external nofollow' rel='external nofollow' > <img src='http://m.cgvv.com.cn/bcjs/${pageContext.request.contextPath}/ShopServlet?method=getShopsShoesImage&shoes_id=<%=shoes.getShoes_id() %>' alt=''></a> </td> <td class='product_name'><a href='http://m.cgvv.com.cn/bcjs/ShopShoesDetails.jsp?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 = ?';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 blocke.printStackTrace(); } }else if(method.equals('addToCart')) { try {addToCart(request, response); } catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace(); } }else if(method.equals('deleteFromCart')) { try {deleteFromCart(request, response); } catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace(); } }else if(method.equals('payFromCart')) { try {payFromCart(request, response); } catch (SQLException e) {// TODO Auto-generated catch blocke.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='http://m.cgvv.com.cn/bcjs/ShopServlet?method=deleteFromCart&shoes_id=' rel='external nofollow' +shoes_id+'&user_id='+22;alert('刪除成功!'); } } else { alert(’請選擇商品!’); } getTotal(); //更新總數 }

以上就是JavaScript中如何調用Java方法的詳細內容,更多關于js中調用Java方法的資料請關注好吧啦網其它相關文章!

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 国产伦久视频免费观看 视频 | 亚洲国产cao | 中文字幕一区二区三区亚洲精品 | 特黄特色三级在线观看 | 狠狠干香蕉 | 成人国产三级在线播放 | a级做爰片毛片视频 | 在线观看中文字幕一区 | 大陆精品自在线拍国语 | 欧美一级欧美一级在线播放 | 日本精品三级 | 日韩免费观看的一级毛片 | 久久福利国产 | 精品视频免费在线观看 | 在线观看 一区 | 国产欧美日本在线 | 二级黄的全免费视频 | 男女在线免费视频 | 91精品久久久久含羞草 | 一本久道综合久久精品 | 香港日本韩国三级网站 | 亚洲国产精品一区二区三区 | 玖玖在线国产精品 | 精品国产成人a在线观看 | 国产亚洲精品成人一区看片 | 最近手机高清中文字幕大全7 | 91成人免费 | www.成人网 | 97dyy影院理论片 | 免费看欧美一级特黄a大片一 | 美女做爰视频在线观看免费 | 高清不卡一区二区三区 | 国产欧美一区二区三区免费看 | 成人做爰视频www在线观看 | 亚洲天堂色视频 | 国内精品2020情侣视频 | 欧美一级高清毛片aaa | 亚洲综合一区二区三区 | 全部免费毛片免费播放 | 国产免费人成在线看视频 | 国产午夜在线观看视频播放 |