色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術(shù)文章
文章詳情頁

JavaScript中如何調(diào)用Java方法

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

在JavaScript中想要調(diào)用Java的方法,我通過JavaScript訪問servlet,再通過servlet調(diào)用Java某個(gè)類的方法。

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'>價(jià)格</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://www.lshqa.cn/bcjs/ShopShoesDetails.jsp?shoes_id=<%=shoes.getShoes_id() %>' rel='external nofollow' rel='external nofollow' > <img src='http://www.lshqa.cn/bcjs/${pageContext.request.contextPath}/ShopServlet?method=getShopsShoesImage&shoes_id=<%=shoes.getShoes_id() %>' alt=''></a> </td> <td class='product_name'><a href='http://www.lshqa.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代碼

// 點(diǎn)擊全部刪除 deleteAll.onclick = function () { if (selectedTotal.innerHTML != 0) { var con = confirm(’確定刪除所選商品嗎?’); //彈出確認(rèn)框 if (con) {var shoes_id = ’’;for (var i = 0; i < tr.length; i++) { // 如果被選中,就刪除相應(yīng)的行 if (tr[i].getElementsByTagName(’input’)[0].checked) { shoes_id = shoes_id + tr[i].cells[0].innerHTML + ’,’;//tr[i].parentNode.removeChild(tr[i]); // 刪除相應(yīng)節(jié)點(diǎn) //i--; //回退下標(biāo)位置 }}alert(shoes_id);window.location.href='http://www.lshqa.cn/bcjs/ShopServlet?method=deleteFromCart&shoes_id=' rel='external nofollow' +shoes_id+'&user_id='+22;alert('刪除成功!'); } } else { alert(’請(qǐng)選擇商品!’); } getTotal(); //更新總數(shù) }

以上就是JavaScript中如何調(diào)用Java方法的詳細(xì)內(nèi)容,更多關(guān)于js中調(diào)用Java方法的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: JavaScript
相關(guān)文章:
主站蜘蛛池模板: 伊人久久大香线焦综合四虎 | 亚洲精品国自产拍影院 | www.久久久| 欧美精品久久久久久久免费观看 | 又黄又免费的网站 | 欧美巨乳在线观看 | 中文字幕成人免费高清在线视频 | 日本亚洲成高清一区二区三区 | 尹人香蕉久久99天天拍 | 欧美日本俄罗斯一级毛片 | 亚洲国产一区二区三区四区五区 | 亚洲国产天堂久久综合网站 | 欧美成人激情 | 国内亚州视频在线观看 | 欧美成人免费观看国产 | 瑟瑟网站在线观看 | 久久永久免费视频 | 亚洲高清视频网站 | 国产手机在线视频放线视频 | 一级做a爰性色毛片免费 | 在线视频亚洲欧美 | 男人干女人的视频 | 欧美一区二区三区播放 | 色站综合 | 国产精品特级毛片一区二区三区 | 亚洲精品国精品久久99热 | 欧美亚洲日本国产 | 欧美性精品hd在线观看 | 国产精品久久久久久免费播放 | 国产成人精品免费久久久久 | 青青草国产一区二区三区 | 久久青草国产手机看片福利盒子 | 男人扒开双腿女人爽视频免费 | 亚洲视频中文字幕在线 | 日本不卡免费高清视频 | 欧美中日韩在线 | 久久福利网站 | 91精品国产欧美一区二区 | 亚洲综合色视频在线观看 | 黄网在线 | 久久久久久全国免费观看 |