批量审核

//全选javascript实现

<script type="text/javascript">

var flag = 1;

function selectAll() {

var subReviewProduct = document.all['subReviewProduct'];

if (flag == 1) {

if (subReviewProduct.length>0) {

for var i = 0; i < subReviewProduct.length; i++)

subReviewProduct[i].checked = true;

else {

subReviewProduct.checked = true;

}

flag = 0;

else {

if (subReviewProduct.length>0) {

for var i = 0; i < subReviewProduct.length; i++)

subReviewProduct[i].checked = false;

else {

subReviewProduct.checked = false;

}

flag = 1;

}

}

</script>

批量审核servlet

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

//设置请求与响应的编码格式

request.setCharacterEncoding("utf-8");

response.setCharacterEncoding("utf-8");

//获得out对象实例

PrintWriter out = response.getWriter();

//获得GoodsInfomationService实例

GoodsInfomationService goodsInfomationService = new GoodsInfomationService();

//从数据库获取所有未审核商品

List<GoodsInformation> goodsInfomationList = goodsInfomationService

.findGoodsBySql("select * from goodsinformation where gStatus=0");

//获取session

HttpSession session = request.getSession();

//将goodsInfomationList存入session

session.setAttribute("goodsInfomationList", goodsInfomationList);

//获取界面submit信息

String submit = request.getParameter("submit");

//如果所获取对象为批量上架,则执行批量审核操作

if ("批 量 上 架".equals(submit)) {

//获取所有被选中复选框name值数组

String[] allReviewProduct = request

.getParameterValues("subReviewProduct");

String gIds = "";

//将获取的复选框数组的值一个一个的传入gIds字符串中("'',''...形式")

for (int i = 0; i < allReviewProduct.length; i++) {

gIds += "'" + allReviewProduct[i] + "'";

if (i != allReviewProduct.length - 1)

gIds += ",";

}

//如果没有选项被选中,提示操作错误

if(gIds.equals(""))

{

out

.print("<script>alert('On a fail');location.replace('ReviewProduct.jsp');</script>");

return;

}

//如果有选项被选中则执行更新

String sql = "update goodsinformation set gStatus=1 where gId in("

+ gIds + ")";

//如果批量操作成功,提示用户批量审核成功,否则提示失败

if (goodsInfomationService.upadteStatusGoodsBySql(sql) > 0) {

out

.print("<script>alert('The batch on success');location.replace('ReviewProduct.jsp');</script>");

else {

out

.print("<script>alert('The batch on fail');location.replace('ReviewProduct.jsp');</script>");

}

else {

//如果用户点击的不是全选复选框,则执行单个商品审核操作

int gId = Integer.parseInt(request.getParameter("gId"));

int gStatus = 1;

if (goodsInfomationService.upadteStatusGoods(gId, gStatus) == 1) {

out.print("<script>alert('On a successful');location.replace('ReviewProduct.jsp');</script>");

else {

out.print("<script>alert('On a fail');location.replace('ReviewProduct.jsp');</script>");

}

}

posted @ 2013-10-22 23:34  esther&  阅读(902)  评论(0)    收藏  举报