function goodsAdd() { var url="<%=path %>/admin/goods/goodsAdd.jsp"; window.location.href=url; }
时间: 2024-05-23 07:13:55 浏览: 14
这是一个 JavaScript 函数,用于在点击按钮时跳转到指定页面。具体来说,它定义了一个名为 goodsAdd 的函数,该函数没有参数。在函数体内,它使用了一个变量 url,该变量的值是一个 JSP 页面的 URL。最后,它通过 window.location.href 属性将页面重定向到这个 URL,从而实现了跳转。这段代码中的 <%=path %> 是一个 JSP 标签,表示应用程序的根目录路径。在实际运行时,该标签会被替换为相应的路径。
相关问题
function jiaoshiDele(id) { if(confirm('您确定删除吗?')) { window.location.href="<%=path %>/jiaoshi?type=jiaoshiDel&id="+id; } } function jiaoshiAdd() { var url="<%=path %>/admin/jiaoshi/jiaoshiAdd.jsp"; window.location.href=url; } </script> </head>
这段代码是 JavaScript 代码,它定义了两个函数:`jiaoshiDele` 和 `jiaoshiAdd`。`jiaoshiDele` 函数会在用户点击确认删除时,将浏览器的页面地址重定向到指定的 URL,以执行删除教师的操作。`jiaoshiAdd` 函数则是将浏览器的页面地址重定向到指定的 URL,以执行添加教师的操作。
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page import="com.test.bean.Goods,java.util.ArrayList" %> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>购物车</title> <style type="text/css"> table{border-collapse:collapse;} td{border:1px solid black; text-align:center; } #deal{margin-left:200px} </style> </head> <body> <jsp:useBean id="cart" class="com.test.bean.Cart" scope="session"></jsp:useBean> <%if(cart==null||cart.getGoodslist().size()==0) out.println("购物车空空如也.....<a href='index.jsp'>返回商品首页</a>"); else{ ArrayList<Goods>goodslist=cart.getGoodslist(); %> <div> 当前购物车共有<%=cart.getGcount() %>件物品 <a href='index.jsp'>返回商品首页</a><br> <table><tr> <td>序号</td> <td>商品号</td> <td>商品名称</td> <td>价格</td> <td>数量</td> <td>小计</td> <td>描述</td></tr> <%for(int i=0;i<goodslist.size();i++){ Goods goods=goodslist.get(i); %> <tr> <td><%=i+1 %></td> <td><%=goods.getGid() %></td> <td><%=goods.getGname() %></td> <td><%= String.format("%.2f", goods.getGprice())%></td> <td><%=goods.getGcount() %></td> <td><%=String.format("%.2f", goods.getGprice()*goods.getGcount()) %></td> <td><a href="<%=request.getContextPath() %>/Servlet/DelCartServlet?gid=<%=goods.getGid() %>">删除</a></td></tr> <%}%> </table><br> <span>总计</span><%=String.format("%.2f",cart.getTotal())%> <input type="button" id="deal" value="购买" /></input> </div> <%}%> <script type="text/javascript"> var dealbutton=document.getElementById("deal"); dealbutton.onclick=function(){ var cf=confirm("确定购买吗?"); if(cf==true){ window.location.href="Servlet/DealServlet"; } } </script> </body> </html> 修改删除功能,在购物车物品数量大于1的情况下点击“删除”时减少1个,等于1时删除此项商品;
要修改删除功能,在购物车物品数量大于1的情况下点击“删除”时,应该减少1个,等于1时则应该删除此项商品。具体实现的代码如下:
1. 在 DelCartServlet 中,判断商品数量是否大于1,若大于1,则减少1个;若等于1,则直接删除此商品。
```
int gid = Integer.parseInt(request.getParameter("gid"));
Cart cart = (Cart) request.getSession().getAttribute("cart");
ArrayList<Goods> goodslist = cart.getGoodslist();
for(int i = 0; i < goodslist.size(); i++) {
Goods goods = goodslist.get(i);
if(goods.getGid() == gid) {
if(goods.getGcount() > 1) {
goods.setGcount(goods.getGcount() - 1);
} else {
goodslist.remove(i);
}
break;
}
}
cart.setGoodslist(goodslist);
response.sendRedirect(request.getContextPath()+"/cart.jsp");
```
2. 在 cart.jsp 中,将删除按钮的链接修改为 DelCartServlet,并传递该商品的 gid 参数。
```
<td><a href="<%=request.getContextPath() %>/Servlet/DelCartServlet?gid=<%=goods.getGid() %>">删除</a></td>
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<body>
<input type="button" value="新增" onclick="add()">
ID
姓名
年龄
密码
修改 删除
<c:if test="${not empty list }">
<c:forEach items="${list }" var="user" varStatus="s">
${s.count}
${user.username}
${user.age}
${user.password}
修改
删除
</c:forEach>
</c:if>
<script >function add(){
location.href="add.jsp";
}
function updatemethod(userid) {
var id = parseInt('<%= session.getAttribute("id") %>');
if (userid != id) {
alert("你不能修改别人的信息");
} else {
window.location.href = "update.jsp";
}
}
function deletemethod(userid) {
var id = parseInt('<%= session.getAttribute("id") %>');
if (userid != id) {
alert("你不能删除别人的信息");
} else {
if(confirm("你确定要删除自己的信息吗?")) {
window.location.href = "index.jsp";
}
}
}</script>
</body>
</html>上述代码哪里报错,要如何修改
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
添加
修改
删除
手动运行数据更新器 选中 时间 总居民消费CPI 食品类CPI 衣着类CPI 居住类CPI 服务类CPI 交通通信类CPI 教育类CPI 医药类CPI 其他类CPI <c:forEach items="${cpi}" var="i"> <input name="radiobox" type="radio" value=${i.TIMES}/> <c:if test="${i.TIMES==999999}"> 预测本月 </c:if> <c:if test="${i.TIMES!=999999}"> ${i.TIMES} </c:if> ${i.CPI} ${i.FOOD} ${i.CLOTH} ${i.RESIDE} ${i.SERVICE} ${i.TRANS} ${i.EDU} ${i.MEDIC} ${i.OTHER} </c:forEach> 我希望页面在点击修改和删除的时候把单选框的value提交给服务器,我应该怎么改
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
如何使用card控件里的图片具有设置地图中心点坐标功能?function setMapCente<body> <script type="text/javascript" class="map"> var map = new BMap.Map("baiduMap"); map.centerAndZoom(new BMap.Point(2.33269, 48.863727), 13); map.addControl(new BMap.MapTypeControl()); map.setCurrentCity("巴黎"); map.enableScrollWheelZoom(true); </script>
安纳西 >
安纳西 >
安纳西 >
安纳西 > </body>r(lat, lng) { var newCenter = new google.maps.LatLng(lat, lng); map.setCenter(newCenter); }
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
请优化这段代码:<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>下拉菜单</title> <style type="text/css"> .nav { margin: 100px; } .nav>li { position: relative; float: left; width: 80px; height: 41px; text-align: center; } .nav li a { display: block; width: 100%; height: 100%; line-height: 41px; color: #333; } /* .nav>li ul{ display: none; position: absolute; top: 20px; right: 21px; } */ </style> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> </head> <body> 微博 私信 评论 @我 留言板 私信 评论 @我 电话 私信 评论 @我 邮箱 私信 评论 @我 <script type="text/javascript"> $(".nav>li").mouseover( function() { $(this).children("ul").show(); } ); $(".nav>li").mouseout( function() { $(this).children("ul").hide(); } ); </script> </body> </html>
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
找出这串代码的错误并给出正确答案<!DOCTYPE html> <?php require_once('./conn.php'); $sql = "select * from result"; $result = $conn->query($sql); if ($result->num_rows>0){ while($row = $result->fetch_assoc()) { ?> <?php echo $row['id'] ?> <?php echo $row['name'] ?> <?php echo $row['age'] ?> <?php echo $row['result'] ?> <button onclick="toUpdate(this)">修改</button> <button onclick="remove(this)">删除</button> <?php } } $conn->close(); ?> <html> <head> <meta charset="utf-8" /> <script type="text/javascript" src="js/index.js"></script> <title>学生成绩管理系统</title> </head> <body> 学生成绩管理系统 <button>添加</button> </body> </html> <script type="text/javascript"> function remove(ele){ let id = ele.parentElement.parentElement.children[0].innerText; window.location.href="remove_server.php?id="+id; } function toUpdate(ele) { let id = ele.parentElement.parentElement.children[0].innerText; window.location.href = "./update.php?id="+id; } </script>
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)