请问为什么ArrayList xx=(ArrayList)session .getAttribute取得的值为空

他会直接跳转到bottom页面,请问为什么ArrayList xx=(ArrayList)session .getAttribute取得的值为空,

img

img


updatePassword的代码如下


```java
<%-- 
    Document   : updatePassword
    Created on : 2012-3-20, 23:58:33
    Author     : Administrator
--%>

<%@page import="ch1.LoginBean"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body bgcolor="CCCFFF">
        <hr noshade>
        <div align="center">
            <table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
                <tr>
                    <td width="33%">
                        <a href="lookMessage.jsp">查看个人信息</a>
                    </td>
                     <td width="33%">
                        <a href="updateMessage.jsp">修改个人信息</a>
                    </td>
                    <td width="33%">
                        修改密码
                    </td>
                </tr>
            </table>
        </div>
        <hr noshade>
        <br><br>
        <form action="UpdatePasswordServlet" method="post">
            <table border="2" cellspacing="0" cellpadding="0" bgcolor="CCCFFF" width="60%" align="center">
         
           <%
        
                  ArrayList login=(ArrayList)session.getAttribute("login");
                if(login==null||login.size()==0){
                    response.sendRedirect("bottom.jsp");
                }else{
                    for(int i=login.size()-1;i>=0;i--){
                        LoginBean nn=(LoginBean)login.get(i);
                  
            %>
           
                <tr>
                    <td height="30">用户密码</td>
                    <td><input type="password" name="password1" value="<%=nn.getPassword()%>"></td>
                </tr>
                <tr>
                    <td height="30">重复密码</td>
                    <td><input type="password" name="password2" value="<%=nn.getPassword()%>"></td>
                </tr>
                <tr>
                    <td colspan="2" align="center">
                        <input type="submit" value="确 定" size="12">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="reset" value="清 除" size="12">
                    </td>
                 </tr>
            <%
                  }
               }
            %>
            </table>
       </form>
    </body>
</html>


```这是UpdatePasswordServlet的
```java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ch1;

import java.io.IOException;
import java.sql.*;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.swing.JOptionPane;
import ch1.LoginBean;

/**
 *
 * @author Administrator
 */
public class UpdatePasswordServlet extends HttpServlet {
    public void wrong1(){
        String msg="不允许有空,修改失败!";
        int type=JOptionPane.YES_NO_CANCEL_OPTION;
        String title="消息提示";
        JOptionPane.showMessageDialog(null, msg, title, type);
    }
    public void wrong2(){
        String msg="两次密码不同,修改失败!";
        int type=JOptionPane.YES_NO_CANCEL_OPTION;
        String title="消息提示";
        JOptionPane.showMessageDialog(null, msg, title, type);
    }
    public void right(){
        String msg="填写信息合格,修改成功!";
        int type=JOptionPane.YES_NO_CANCEL_OPTION;
        String title="消息提示";
        JOptionPane.showMessageDialog(null, msg, title, type);
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        String password1=new String(request.getParameter("password1").getBytes("ISO-8859-1"),"UTF-8");
        String password2=new String(request.getParameter("password2").getBytes("ISO-8859-1"),"UTF-8");
        if(password1.length()==0||password2.length()==0){
            wrong1();
            response.sendRedirect("updatePassword.jsp");
        }else if(!(password1.equals(password2))){
            wrong2();
            response.sendRedirect("updatePassword.jsp");
        }else{
            try{
                Connection con=null;
                Statement stmt=null;
                ResultSet rs=null;
                Class.forName("com.mysql.jdbc.Driver");
                String url="jdbc:mysql://localhost:3306/person?useUnicode=true&characterEncoding=gbk";
                con=DriverManager.getConnection(url,"root","123456");
                stmt=con.createStatement();
                String userName="";
                HttpSession session=request.getSession();
                ArrayList login=(ArrayList)session.getAttribute("login");
               if(login==null||login.size()==0){
                    response.sendRedirect("login.jsp");
               }else{
                    for(int i=login.size()-1;i>=0;i--){
                         LoginBean nn=(LoginBean)login.get(i);
                         userName=nn.getUserName();
                    }
                }
                String sql1="Update user set password='"+password1+"' where userName='"+userName+"'";
                stmt.executeUpdate(sql1);
                String sql2="select * from user where userName='"+userName+"'";
                rs=stmt.executeQuery(sql2);
                LoginBean nn=new LoginBean();
                nn.setPassword(password1);
                ArrayList wordlist=null;
                wordlist=new ArrayList();
                wordlist.add(nn);
                session.setAttribute("login", login);
                rs.close();
                stmt.close();
                con.close();
                right();
                response.sendRedirect("lookMessage.jsp");
            }catch(Exception e){
                e.printStackTrace();
            }
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        doGet(request, response);
    }

}


这是LoginBean 的
package ch1;

public class LoginBean {
    private String userName;
    private String password;
    public LoginBean(){
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
}


```

代码贴全