⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 updateproduct.jsp

📁 简单的企业宣传的网站
💻 JSP
字号:
<%@ page language="java" import="java.util.*,entity.*,dao.*" pageEncoding="gbk"%>
<%@ include file="checksession.jsp" %>
<html>
  <head>
    
    <title>My JSP 'updateProduct.jsp' starting page</title>
 	<link rel="stylesheet" href="../css/style_admin.css" type="text/css">
 	<%
 		response.setCharacterEncoding("gbk");
 		String action=request.getParameter("action");
 		String productID=request.getParameter("productID");
 		Product product=new Product();
 		ProductDao productDao=new ProductDao();
 		
 		if(action!=null&&"update".equals(action))
 		{
 			String serialNumber=request.getParameter("serialNumber");
 			String name=request.getParameter("name");
 			String brand=request.getParameter("brand");
 			String model=request.getParameter("model");
 			String price=request.getParameter("price");
 			String picture=request.getParameter("picture");
 			String description=request.getParameter("description");
 			
 			product.setProductID(Integer.parseInt(productID));
 			product.setSerialNumber(serialNumber);
 			product.setName(name);
 			product.setBrand(brand);
 			product.setModel(model);
 			product.setPrice(Double.parseDouble(price));
 			product.setPicture(picture);
 			product.setDescription(description);
 			
 			int count=productDao.updateProduct(product);
 			if(count>0)
 			{
 				out.print("<script type='text/javascript'>alert('成功修改一条商品信息!');location.replace('manageProduct.jsp');</script>");
 			}else
 			{
 				out.print("<script type='text/javascript'>alert('修改失败!');history.go(-1);</script>");
 			}
 		}else
 		{
 			product=productDao.findProductByID(productID);
 		}
 	 %>
 	
 	<script type="text/javascript">
 	 	function checkform()
	 {
	 	if(document.form1.serialNumber.value==null)
	 	{
	 		alert("商品编号不能为空!");
	 		return false;
	 	}else if(document.form1.name.value==null)
	 	{
	 		alert("商品名称不能为空!");
	 		return false;
	 	}else if(document.form1.brand.value==null)
	 	{
			alert("商品商标不能为空!");
			return false;
	 	}else if(document.form1.model.value==null)
	 	{
	 		alert("商品型号不能为空!");
	 		return false;
	 	}else if(document.form1.price.value==null)
	 	{
	 		alert("商品价格不能为空!");
	 		return false;
	 		if(!isNaN(document.form1.price.value))
	 		{
	 			alert("");
	 			return false;
	 		}
	 	}else
	 	{
			return true;
	 	}
	 }
	 function checkIsFloat()
	 	{
	 		var nc=event.keyCode;
	 		if(nc<48||nc>57)
	 		{
	 			if(nc==46)
	 			{
					var s=document.form1.price.value;
					for(int i=0;i<s.length;i++)
					{
						if(s.charAt(i)==".")
						{
							event.keyCode=0;
							return;
						}
					}
	 			}else
	 			{
	 				event.keyCode=0;
	 				return;
	 			}
	 		}
	 	}
 	 </script>
  </head>
  
  <body>
    <form action="updateProduct.jsp" name="form1" method="post" onSubmit="return checkform()">
    	<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableborder">
    		<input name="action" type="hidden" value="update">
    		<input name="productID" type="hidden" value="<%=productID %>">
    		<tr>
    			<td colspan="2" class="header">添加商品信息</td>
    		</tr>
    		<tr>
    			<td class="altbg1">商品编号:</td>
    			<td class="altbg2">
    				<input name="serialNumber" type="text" size="40" value="<%=product.getSerialNumber() %>">
    			</td>
    		</tr>
    		<tr>
    			<td class="altbg1">商品名称:</td>
    			<td class="altbg2">
    				<input name="name" type="text" size="40" value="<%=product.getName() %>">
    			</td>
    		</tr>
    		<tr>
    			<td class="altbg1">商品商标:</td>
    			<td class="altbg2">
    				<input name="brand" type="text" size="40" value="<%=product.getBrand() %>">
    			</td>
    		</tr>
    		<tr>
    			<td class="altbg1">商品型号:</td>
    			<td class="altbg2">
    				<input name="model" type="text" size="40" value="<%=product.getModel() %>">
    			</td>
    		</tr>
    		<tr>
    			<td class="altbg1">商品价格:</td>
    			<td class="altbg2">
    				<input name="price" type="text" size="40" onkeypress="checkIsFloat()" value="<%=product.getPrice() %>">
    			</td>
    		</tr>
    		<tr>
    			<td class="altbg1">商品图片:</td>
    			<td class="altbg2">
    				<input name="picture" type="text" size="40" value="<%=product.getPicture() %>">
    			</td>
    		</tr>
    		<tr>
    			<td class="altbg1">商品介绍:</td>
    			<td class="altbg2">
    				<textarea name="description" rows="5" cols="60"><%=product.getDescription().trim() %></textarea>
    			</td>
    		</tr>
    		<tr>
    			<td class="altbg1">&nbsp;</td>
    			<td class="altbg2">
    				<input name="submit" type="Submit" value="提交">
    				&nbsp;
    				<input name="reset" type="Reset" value="重置">
    			</td>
    		</tr>
    	</table>
    </form>
  </body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -