日期:2014-05-20  浏览次数:20942 次

List数组的使用
我在登录时想把用户名,它的ID,还有他的mail_number(邮件数)全都放在session中去!
现在action中登录成功后还没返回前,把它们放进去?
action中的部分代码:
List   list   =   memberdao.info(userName);
int   mId   =   Integer.valueOf(list.get(mId));         //有错

HttpSession   session   =   request.getSession();
session.setAttribute( "username ",   userName);

memberdao.info()方法中是这样的:
public   List   info(String   username){

List   list   =   new   ArrayList();

ResultSet   rs   =   this.doExcuteQuery( "select   mId,mail_number   from   member   where   =   ' "+username+ " ' ");
try   {
while(rs.next()){
String   mId   =   rs.getString( "mId ");
String   mail_number   =   rs.getString( "mail_number ");
list.add(mId);
list.add(mail_number);
}
}   catch   (SQLException   e)   {

e.printStackTrace();
}

return   list;
}
我改怎么改正???

------解决方案--------------------
你为什么要放到List里面呢,你没有用户bean吗,应该把用户放到List里面去
------解决方案--------------------

List <XXXBean> list = new ArrayList <XXXBean> ();

ResultSet rs = this.doExcuteQuery( "select mId,mail_number from member where = ' "+username+ " ' ");
try {
while(rs.next()){
XXXBean bean = new XXXBean();
bean.setMId(rs.getString( "mId "));
bean.setMailNumber(rs.getString( "mail_number "));
list.add(bean);
}
------解决方案--------------------
把从数据库得到的信息放到bean里面,不应该直接放到List,然后把bean再放到List,需要用的时候直接从List里面取