空对象 session
以下是部分代码
shop.java中的getProduct
public Product getProduct(int proid){ Product pro = null; if(proid!=0){ String sqlpro = "SELECT * from product WHERE PROID="+proid; rs = exe.query(sqlpro); try { if(rs!= null){ pro = new Product(); rs.next(); pro.setProid(rs.getInt("PROID")); pro.setContents(rs.getString("CONTENTS")); pro.setDescript(rs.getString("DESCRIPT")); pro.setName(rs.getString("NAME")); pro.setPrice(rs.getDouble("PRICE")); pro.setSalecount(rs.getInt("SALECOUNT")); pro.setSleprice(rs.getDouble("SALEPRICE")); pro.setSortid(rs.getInt("SORTID")); pro.setDate(rs.getDate("SALEDATE")); } } catch (SQLException e) { e.printStackTrace(); } } return pro; }
int proid = Integer.parseInt(request.getParameter("proid")); Product pro = new Product(); pro = shop.getProduct(proid); session.setAttribute(Contants.CUR_PRODUECT_KEY, pro); response.sendRedirect("detail.jsp");
Product pro = new Product(); pro = (Product)session.getAttribute(Contants.CUR_PRODUECT_KEY); String str =""; if(pro!=null) out.print("not null"); if(pro == null) out.print("go on");