servlet
private void orderlist(HttpServletRequest req, HttpServletResponse resp) {
System.out.println("com to orderlist");
User user = (User) req.getSession().getAttribute(Contacts.USER_SESSION);
UserDao mapper = sqlSession.getMapper(UserDao.class);
List<User> userList = mapper.selectOrderByUserName(user.getUser_name());
req.getSession().setAttribute(Contacts.USER_ORDER,userList);
try {
req.getRequestDispatcher("index/orderlist.jsp").forward(req, resp);
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
js
<table border="0" cellspacing="0" cellpadding="0"
class="table table-hover table-striped font12 table-bordered v-align-top">
<tr>
<th style="width:10%;">航班号</th>
<th style="width:15%;">乘机人</th>
<th style="width:18%;">乘机日期</th>
<th style="width:10%;">舱位</th>
<th style="width:17%;">乘客证件</th>
<th style="width:15%;">联系人</th>
<th style="width:15%;">联系电话</th>
</tr>
<%
List<UserOrder> attribute = (List<UserOrder>) request.getAttribute(Contacts.USER_ORDER);
for (UserOrder order:attribute) {
%>
<tr>
<td>
<%=order.getFlight_number() %>
</td>
<td><p><%=order.getPassenger_name() %></p></td>
<td><%=order.getDate() %></td>
<td><%=order.getFlight_class() %></td>
<td><%=order.getPassenger_id() %></td>
<td><%=order.getContact() %></td>
<td><%=order.getContact_phone() %></td>
</tr>
<%
}
%>
</table>
tomcat报错:
当我看到空指针异常时嘴角微微上扬,又是这个错但是当我重新检查时,发现又没有错误
突然想起自己当时在写这一段的时候不知为什么加了getSession()
然后我将上面的代码改成下面这样时错误又解决了
所以getSession().getAttribute()和直接getAttribute()有什么区别我也不是很清楚.
就先先纪念一下自己遇到的问题吧