为了账号安全,请及时绑定邮箱和手机立即绑定

WEB数据库session的内容get……不到?

WEB数据库session的内容get……不到?

qq_22_7 2017-12-09 00:20:51
JSP:<div class="person_main" align="center">    <table cellspacing="10" cellpadding="10" align="center" width="65%">    <%    ArrayList lookList = (ArrayList)session.getAttribute("lookList");    if(lookList==null||lookList.size()==0){        request.getRequestDispatcher("My.jsp").forward(request, response);        }    else{        for(int i=lookList.size()-1;i>=0;i--){        MyMessBean mm = (MyMessBean)lookList.get(i);     %>         <tr>         <td height="30px">用户姓名</td>         <td><%=mm.getName() %></td>     </tr>      <tr>         <td height="30px">用户账号</td>         <td><%=mm.getId() %></td>     </tr>      <tr>         <td height="30px">用户性别</td>         <td><%=mm.getSex() %></td>     </tr>      <tr>         <td height="30px">用户学历</td>         <td><%=mm.getEdu() %></td>     </tr><%}} %>Servlet:protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        String userId = request.getParameter("userId");        try{            Connection conn = null;            Statement stmt = null;            ResultSet rs = null;            Class.forName("com.mysql.jdbc.Driver");            String url = "jdbc:mysql://localhost:3306/javaweb?useUnicode=true&characterEncoding=utf-8&useSSL=false";            conn = DriverManager.getConnection(url,"root","1997YJY");            stmt=conn.createStatement();            HttpSession session = request.getSession();                        String sql ="select userId,userName,sex,edu from user where userId='"+userId+"'";            rs=stmt.executeQuery(sql);                                    ArrayList lookList = new ArrayList();            while(rs.next()){                MyMessBean mm = new MyMessBean();                mm.setId(rs.getString("userId"));                mm.setName(rs.getString("userName"));                                mm.setSex(rs.getString("sex"));                mm.setEdu(rs.getString("edu"));                lookList.add(mm);                            }            session.setAttribute("lookList", lookList);                                    rs.close();            stmt.close();            conn.close();            request.getRequestDispatcher("person.jsp").forward(request, response);        }catch(Exception e){            e.printStackTrace();        }    }bean:(geter seter方法)    private String userId;    private String userName;    private String edu;    private String sex;可是问题就是这个输出数据库信息的,得到的结果是lookList=null,为什么呢?小白求教,想要知道我该怎样改正,才能转发我要的那个页面:(拜托啦
查看完整描述

目前暂无任何回答

  • 0 回答
  • 0 关注
  • 1088 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信