我写了一个类,下面有查询的方法
public static JSONArray getOder(HttpServletRequest request) {
JSONArray jsonArray = null;
String oderid = StringUtil.getRequestString(request,"id");
String orderid = StringUtil.getRequestString(request,"orderid");
String price = StringUtil.getRequestString(request,"price");
String quantity = StringUtil.getRequestString(request,"quantity");
String shop_id = StringUtil.getRequestString(request,"shop_id");
String subtotal = StringUtil.getRequestString(request,"subtotal");
StringBuffer sql = new StringBuffer(" select orderid,quantity,shop_id,subtotal,name,price from ORDER_DETAIL where 1=1 and orderid="+oderid);

List<DynaBean> list =  DataBaseOperator.queryList(sql.toString());
    jsonArray = JsonUtil.listDynaBeanToJson(list);
    return jsonArray;
    在JS里排版FOR循环输出JSP页面数组
<%
JSONArray jsonArray = ManagerService.getOder(request);
%>
<script type="text/javascript">
   var dataArray= <%=jsonArray%>;
  
    </script>
   我想在查询的时候 如果数据库返回为空,则在跳转的页面提示为空,请问在哪里判断比较好呢? 该怎么判断呢?

解决方案 »

  1.   

    我想在查询的时候 如果数据库返回为空,则在跳转的页面提示为空,请问在哪里判断比较好呢? 该怎么判断呢?在后台,List<DynaBean> list = DataBaseOperator.queryList(sql.toString());
    if(list.size<1){
    return null;
    }else{jsonArray = JsonUtil.listDynaBeanToJson(list);
    return jsonArray;
    }
      

  2.   

    JSP页面数组
    <%
    JSONArray jsonArray = ManagerService.getOder(request);
    if(jsonArray  == null){
     response.sendRedirect("main.jsp");
    }
    %>
      

  3.   

    <script type="text/javascript">
    var dataArray= <%=jsonArray%>;
    if (!dataArray) alert("没东西啊!");
    </script>