商品管理系统
<%@ page language=“java” contentType=“text/html; charset=UTF-8”
pageEncoding=“UTF-8”%>
<%@ page import=“com.base.only.day802.ProductService”%>
<%@ page import=“com.base.only.day802.Product”%>
<%@ page import=“java.text.SimpleDateFormat”%>
<%@ page import=“java.util.ArrayList”%>
商品管理
确定<thead>
<tr>
<th>名字</th>
<th>种类</th>
<th>价格</th>
<th>删除</th>
</tr>
</thead>
<tbody>
<% ArrayList<Product> hms=(ArrayList<Product>)session.getAttribute("homelist");
if(hms==null){
hms=new ArrayList();
}
for(int i=0;i<hms.size();i++){
Product hm=hms.get(i);
%>
<tr>
<td><%=hm.getName() %>
</td>
<td><%=hm.getCategory() %>
</td>
<td><%=hm.getPrice() %>
</td>
<td><button type="button" class="btn btn-warning btn-sm" name="delete"id=<%=hm.getId() %>>×</button></td>
</tr>
<%} %>
</tbody>
<!-- 模态框底部 -->
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
</div>
</div>
<thead>
<tr>
<th>名字</th>
<th>种类</th>
<th>价格</th>
<th>删除</th>
</tr>
</thead>
<tbody>
<%ProductService productService = new ProductService();
ArrayList<Product> hs=(ArrayList<Product>)productService.selectAll();
if(hs==null){
hs=new ArrayList();
}
for(int i=0;i<hs.size();i++){
Product hm=hs.get(i);
%>
<tr>
<td><%=hm.getName() %>
</td>
<td><%=hm.getCategory() %>
</td>
<td><%=hm.getPrice() %>
</td>
<td><button type="button" class="btn btn-warning btn-sm" name="delete"id=<%=hm.getId() %>>×</button></td>
</tr>
<%} %>
</tbody>
增加商品
$(document).ready(function(){
// 在这里写你的代码…
$("button[name='delete']").click( function() {
alert("删除完成")
//alert("你点我了"+this.id);
var rid=this.id;
$.getJSON("DeleteServlet", { hid: rid }, function(json){
});
});
$("button[name='change']").click( function() {
// alert("删除完成")
//alert("你点我了"+this.id);
var oldPassword = $("#oldPassword").val();//获取表单的输入值;
var rid=this.id;
$.getJSON("DeleteServlet", { hid: rid ,hid2: Password}, function(json){
});
});
});
Product hs=new Product();
String hid=request.getParameter("hid");
try {
int a = Integer.parseInt(hid);
ProductService dd=new ProductService();
dd.remove(a);
} catch (NumberFormatException e) {
e.printStackTrace();
}
//ArrayList<SubmitVo> ls=hs.getHomeworkdetailByMasterId2(hid);
//对象,转json格式字符串
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
//String rs=JSONObject.toJSONString(ls);
//response.getWriter().append(rs);
response.sendRedirect("product1.jsp");
}
3
String cname=request.getParameter(“ccname”);
ProductService ps = new ProductService();
System.out.println(cname);
ArrayList<Product> hms=ps.findByName(cname);
HttpSession se1=request.getSession();
se1.setAttribute("homelist", hms);
response.sendRedirect("product2.jsp");
}