在网上看已仁兄说这样可以传数组,按照他的方法去做,结果不知道哪错了,老是空指针
dingdang11.jsp部分代码:
String[] str=new String[99];  
for(;i>str.length;i++){
ResultSet rs_orderid=conn.executeQuery("select orderid from order_item where username='"+session.getAttribute("username")+"'  and  teaid='"+id+"' and number='"+number+"' and price='"+price+"' ");
while(rs_orderid.next()){
int orderid=rs_orderid.getInt(1);
str[i]=(String)orderid;dingdang12.jsp部分代码:String[] str=(String[])session.getAttribute( "str");  
out.print(str.length);
断电测试发现str是空的。该怎么改?

解决方案 »

  1.   

    String[] str=(String[])session.getAttribute( "str");   
    你在哪里使用setAttribute了?
      

  2.   

    String[] str=new String[99];
    while(rs_orderid.next()){
    int orderid=rs_orderid.getInt(1);
    str[i]=(String)orderid;}
    session.setAttribute("str",str);
      

  3.   

    还是用List等collection比较好。
      

  4.   

    不要把 HttpSession 对象作为数据承载容器,虽然可以这么做,但是如果用户量一多,会导致服务器内存极剧地损耗。
      

  5.   

    你没存值,到哪儿取呢?setAtrribute呢?
      

  6.   

    空指针异常 可能是因为 session.getAttribute("username")没有获得值 
    设置Attribute的方法 session.setAttribute("键","值")
    获得Attribute的方法 session.getAttribute("键")