mysql 数据库,如果信息存在调出,如果不存在转到另一个jsp中
如题,如果product数据库中有查询的内容,forward到search.jsp, 如果product数据库中没有查询的数据,forward到noproduct.jsp
怎么改写这里,每次都是不能显示noproduct.jsp
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ActionForward forward = null;
Connection con = null;;
Statement st = null;
HttpSession session = request.getSession();
SearchitemForm searchitemForm = (SearchitemForm) form;
String search = searchitemForm.getSearch();
String strSql = "select * from product where product='" + search + "';";
ResultSet rsLogon = null;
try{
DataSource dataSource = getDataSource(request,"datasource");
con = dataSource.getConnection();
st = con.createStatement();
rsLogon = st.executeQuery(strSql);
ArrayList a=new ArrayList();
while(rsLogon.next()){
String Product=rsLogon.getString("product");
String Price=rsLogon.getString("price");
String Description=rsLogon.getString("description");
String Barcode = rsLogon.getString("barcode");
Product m=new Product();
m.setProduct(Product);
m.setPrice(Price);
m.setDescription(Description);
m.setBarcode(Barcode);
a.add(m);
}
session.setAttribute("b", a);
forward = mapping.findForward("search");
}
catch(
SQLException e){
System.out.println(e.getMessage());
}
return forward;
}
}
------解决方案--------------------判断得到的数据行数,然后判断一下是否大于0,跳到指定页面即可!
------解决方案--------------------判断下rsLogon的size,为0跳转提示页。