以下是部分代码
shop.java中的getProductpublic 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;
}detailServletint 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");detail.jspProduct 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");为什么pro为Null
shop.java中的getProductpublic 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;
}detailServletint 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");detail.jspProduct 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");为什么pro为Null
1.proid的值有没有正确传递detailServlet
2.在数据库中是否存在PROID=proid的数据
shop.java
你看下proid是何值?
然后看下数据库中有对应的记录没,如果有看下shop.java里查询的代码是否不正常
[code=Html]
<form action="DetailServlet">
<a href="detail.jsp?proid=<%=pro.getProid() %>">asdf</a>
</form>
点击这个链接,我在DetailServlet中request.getParameter("proid")能取到吗
[/Html]