📄 goodsadd.jsp
字号:
<%@ page language="java" import="java.util.*,com.test.ps.goods.*"pageEncoding="UTF-8"%>
<%@page import="com.test.ps.util.TransStr;"%>
<%
int cateId=Integer.parseInt(request.getParameter("categoryId"));
int parId=Integer.parseInt(request.getParameter("parId"));
String action = request.getParameter("action");
//处理提交
if(action!=null&& action.trim().equals("submit")){
String goodsCode=request.getParameter("goodsCode");
String goodsName=TransStr.transStr(request.getParameter("goodsName"));
String categoryId=request.getParameter("categoryId");
String goodsImage="image/pic/"+goodsCode+".jpg";
String goodsPrice=request.getParameter("goodsPrice");
String descr=TransStr.transStr(request.getParameter("desc"));
String hotgoods=request.getParameter("onSale");
Date gdate =new Date();
Goods good=new Goods();
good.setGoodsCode(goodsCode);
good.setGoodsName(goodsName);
good.setCategoryId(Integer.parseInt(categoryId));
good.setGoodsImage(goodsImage);
good.setGoodsPrice(Float.valueOf(goodsPrice));
good.setDescr(descr);
good.setHotgoods(hotgoods);
good.setGDate(gdate);
if(GoodsAction.checkName(good)==1)
out.print("<script>alert('商品名已存在!');history.back();</script>");
else if(GoodsAction.checkCode(good)==1)
out.print("<script>alert('商品编号已存在!');history.back();</script>");
else{
GoodsAction.addGoods(good);
out.print("<script>alert('商品添加成功!');</script>");
response.sendRedirect("goodsList.jsp?cateId="+cateId+"&parId="+parId);
}
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加商品</title>
<LINK href="../img/adminStyle.css" type=text/css rel=stylesheet>
<script type="text/javascript">
//检查商品编号格式
function checkCode(o)
{
var check=/^([a -zA-Z0-9]){6,20}$/;
if(o.value==""){
document.all.errCode.innerHTML="* <span style=\"color:#FF0000\">商品编号不能为空</span>";
document.all.submitToAdd.disabled=true;
}
else if(!check.exec(o.value)){
document.all.errCode.innerHTML="* <span style=\"color:#FF0000\">商品编号必须为6-20位的数字或字母</span>";
document.all.submitToAdd.disabled=true;
}
else{
document.all.errCode.innerHTML="*";
document.all.isCodeRight.value="right";
if(document.all.isPriceRight.value=="right"&&document.all.isNameRight.value=="right")
document.all.submitToAdd.disabled=false;
}
}
//检查商品名格式
function checkName(o)
{
var errName=document.getElementById("errName");
var check=/^([^u4E00-u9FA5]|[a-zA-Z0-9]){1}+([^u4E00-u9FA5]|[a-zA-Z0-9]|[._-]){5,29}$/;
if(o.value==""){
errName.innerHTML="* <span style=\"color:#FF0000\">商品名不能为空</span>";
document.all.submitToAdd.disabled=true;
}
else if(!check.exec(o.value)){
errName.innerHTML="* <span style=\"color:#FF0000\">商品名必须为6-30位的字母、数字或中文</span>";
document.all.submitToAdd.disabled=true;
}
else{
errName.innerHTML="*";
document.all.isNameRight.value="right";
if(document.all.isPriceRight.value=="right"&&document.all.isCodeRight.value=="right")
document.all.submitToAdd.disabled=false;
}
}
//检查价格格式
function checkPrice(o)
{
var errPrice=document.getElementById("errPrice");
var check=/^(([1-9][0-9]{0,17})|0)$/;
if(o.value==""){
errPrice.innerHTML="* <span style=\"color:#FF0000\">商品价格不能为空</span>";
document.all.submitToAdd.disabled=true;
}
else if(!check.exec(o.value)){
errPrice.innerHTML="* <span style=\"color:#FF0000\">请输入18位以下数字</span>";
document.all.submitToAdd.disabled=true;
}
else{
errPrice.innerHTML="*";
document.all.isPriceRight.value="right";
if(document.all.isNameRight.value=="right"&&document.all.isCodeRight.value=="right")
document.all.submitToAdd.disabled=false;
}
}
//弹出上传图片窗口
function uploadPic(){
if(document.all.isCodeRight.value=="false")
alert("请先填写商品编号");
else{
window.open("uploadPic.jsp?goodsCode="+document.all.goodsCode.value,"上传图片",
"height=100, width=400, toolbar=no, menubar=no, scrollbars=no, resizable=yes,status=no,location=no,dependent=yes,hotkeys=yes,left=400,top=200,z-look=yes");
}
}
</script>
<style type="text/css">
.STYLE2 {font-weight: bold}
</style>
</head>
<body>
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="80" colspan="3">
<jsp:include page="../adminTop.jsp" flush="true"/></td>
</tr>
<tr>
<td colspan="3" height="30" bgcolor="#e6f3ff"><span class="STYLE2 STYLE2"><a href="../adminRight.jsp">首页</a>><a href="javascript:history.go(-1)">商品列表</a>>添加商品</span></td>
</tr>
<tr>
<td colspan="3" height="30"><hr size="5" color="#e6f3ff" /></td>
</tr>
<tr>
<td height="30"><h1>添加商品</h1></td>
</tr>
<tr>
<td height="30" valign="top">
<form action="" method="post" name="goodsForm" id="goodsAdd">
<table height="360" width="677" border="0" align="left" cellpadding="0" cellspacing="0">
<input type="hidden" name="isNameRight" value="false" />
<input type="hidden" name="isPriceRight" value="false" />
<input type="hidden" name="isCodeRight" value="false" />
<input type="hidden" name="action" value="submit" />
<input type="hidden" name="categoryId" value="<%=cateId%>" />
<tr>
<td width="73" rowspan="7"> </td>
<td width="75"><div align="center">商品编号</div></td>
<td colspan="2"><label>
<input type="text" name="goodsCode" size="25" onBlur="checkCode(this)" />
</label></td>
<td><div id="errCode">
<div align="left">*</div>
</div></td>
</tr>
<tr>
<td><div align="center">名称</div></td>
<td colspan="2"><label>
<input type="text" name="goodsName" size="25" onBlur="checkName(this)" />
</label></td>
<td><div id="errName">
<div align="left">*</div>
</div></td>
</tr>
<tr>
<td><div align="center">图片</div></td>
<td colspan="2"><input type="button" name="upLoadImg" value="点击上传图片" onClick="uploadPic()" /></td>
<td><br /></td>
</tr>
<tr>
<td><div align="center">价格</div></td>
<td colspan="2"><label>
<input type="text" name="goodsPrice" size="25" onBlur="checkPrice(this)" />
</label></td>
<td><div id="errPrice">
<div align="left">*</div>
</div></td>
</tr>
<tr>
<td valign="top" height="120"><div align="center">详细描述</div></td>
<td colspan="3" valign="top"><label>
<textarea name="desc" rows="12" cols="30"></textarea>
</label></td>
</tr>
<tr>
<td><div align="center">是否热卖</div></td>
<td width="68"><label>
<input type="radio" name="onSale" value="1" />是 </label></td>
<td width="111"><label>
<input type="radio" name="onSale" value="0" checked="checked" />否</label></td>
<td width="350"> </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submitToAdd" value="确认添加" disabled="disabled" /></td>
<td colspan="3"> </td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td><hr align="left" size="10" noshade color="#318EB7"></td>
</tr>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -