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,为什么呢?小白求教,想要知道我该怎样改正,才能转发我要的那个页面:(拜托啦