Web编程技术补考模拟试卷(B卷)

} public String getName() { return name; } public void setName(String name) { this.name = name; } public String getBrand() { return brand; } public void setBrand(String brand) { this.brand = brand; } public String getModel() { return model; } public void setModel(String model) { this.model = model; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public String getPicture() { return picture; } public void setPicture(String picture) { this.picture = picture; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } }

Impl:定义接口 package cn.jmu.dao; import java.util.*;

import cn.jmu.vo.Product;

public interface IProductDAO {

public ArrayList getAllNextGoods(int page,int pageCount) throws Exception; public ArrayList getAllGoods()throws Exception; public int getPages(int pageCount)throws Exception; public Product getOneGood(int pid)throws Exception; public boolean addNew(Product product)throws Exception; public boolean updateOneGood(Product product)throws Exception; public boolean delGood(int pid)throws Exception; public boolean goodsDel(int [] pids)throws Exception; }

Dao.impl:具体实现类 package cn.jmu.dao.impl; import java.util.ArrayList;

import cn.jmu.dao.IProductDAO; import cn.jmu.vo.Product; import java.sql.*; import java.util.*; import cn.jmu.dbc.*;

public class ProductDAOImpl implements IProductDAO { /* * 添加新商品 * 参数:新商品信息的类对象 */ public boolean addNew(Product product) throws Exception { boolean result=false; Connection con=null; PreparedStatement pstmt=null; try { con=ConnectionManager.getCon(); pstmt=con.prepareStatement(\ pstmt.setString(1, product.getSerialNumber()); pstmt.setString(2, product.getName()); pstmt.setString(3, product.getBrand()); pstmt.setString(4, product.getModel()); pstmt.setDouble(5, product.getPrice()); pstmt.setString(6, product.getPicture()); pstmt.setString(7, product.getDescription()); int count=pstmt.executeUpdate(); if (count==1) { result=true; } } catch (Exception e) { System.out.println(e); }finally{ ConnectionManager.closeAll(con, pstmt, null);

} return result; // TODO Auto-generated method stub } }

前台addProduct.jsp

<%--商品展示:接收参数,处理添加的新商品信息--%> <%

request.setCharacterEncoding(\

String num=(String)request.getParameter(\ String name=(String)request.getParameter(\ String brand=(String)request.getParameter(\ String model=(String)request.getParameter(\ String picture=(String)request.getParameter(\

double price=Double.parseDouble(request.getParameter(\ String desciption=(String)request.getParameter(\ ProductDAOImpl pDao=new ProductDAOImpl(); Product product=new Product(); product.setName(name); product.setBrand(brand); product.setModel(model);

product.setSerialNumber(num); product.setPicture(picture);

product.setDescription(desciption); product.setPrice(price); if(pDao.addNew(product)){ out.print(\添加新商品成功!');location='manageProduct.jsp'\ }else{ out.print(\添加新商品失败!');location='addProduct.jsp'\ } %>

<%--商品展示:接收参数,处理添加的新商品信息--%>

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4