日期:2014-05-17  浏览次数:20944 次

JSP 网上商城为什么修改不了产品的信息??
Java code

<%
    request.setCharacterEncoding("GBK");
    int id = Integer.parseInt(request.getParameter("id"));
    Product p = ProductMgr.getInstance().loadById(id);
    String action = request.getParameter("add");
    if (action != null && action.trim().equals("add")) {
        String name = request.getParameter("name");
        double normalPrice = Double.parseDouble(request.getParameter("normalPrice"));
        double memberPrice = Double.parseDouble(request.getParameter("memberPrice"));
        int categoryId = Integer.parseInt(request.getParameter("categoryId"));
        String descr = request.getParameter("descr");
        p.setName(name);
        p.setNormalPrice(normalPrice);
        p.setMemberPrice(memberPrice);
        p.setDescr(descr);
        p.setCategoryId(categoryId);
        p.setPdate(new Date());
        ProductMgr.getInstance().update(p);
        out.print("修改成功");
        
    }
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <title>产品信息修改</title>
    </head>

    <body>
        <form action="ProductModify.jsp" name="productmodify" method="post">
            <table border="1" align="center">
                <input type="hidden" name="action" value="add" />
                <input type="hidden" name="id" value="<%=id %>"/>
                <tr>
                    <td>
                        产品名称:
                    </td>
                    <td>
                        <input name="name" size="25" maxlength="25" type="text"
                            value="<%=p.getName()%>">
                </tr>

                <tr>
                    <td>
                        市场价格:
                    </td>
                    <td>
                        <input name="normalPrice" size="25" type="text"
                            value="<%=p.getNormalPrice()%>">
                    </td>
                </tr>
                <tr>
                    <td>
                        会员价格:
                    </td>
                    <td>
                        <input name="memberPrice" size="25" type="text"
                            value="<%=p.getMemberPrice()%>">
                    </td>
                </tr>

                <tr>
                    <td>
                        所属类别
                    </td>
                    <td>
                        <select name="categoryId">
                            <%
                                List<Category> categories = CategoryService.getInstance()
                                        .getCategories();
                                for (Iterator<Category> it = categories.iterator(); it.hasNext();) {
                                    Category c = it.next();
                                    String selected = "";
                                    if (c.getId() == p.getCategoryId())
                                        selected = "selected";
                                    String preStr = "";
                                    for (int i = 1; i < c.getGrade(); i++)
                                        preStr += "--";
                            %>