structs2框架下连接mysql数据库显示list结果到jsp页面问题
本人在做一个基于structs2框架的web项目,问题核心代码如下:1、页面代码:结果显示使用的迭代器
<form id="showMember" method="post" action="member">
<input id="showAll" type="submit" value="显示全部成员" />
</form>
2、action代码:默认执行execute(),但是报错的时候说是showall()里面的memberlist = memberService.queryAll();这一行有错误。
/**
* 查看该用户的所有成员
*/
public String execute() throws Exception {
memberlist = memberService.queryAll();// 获取当前登录用户的所有成员
System.out.println(memberlist.size());// 输出成员数
return "listall";
}
/**
* 显示该用户的所有成员
*/
public String showall() {
memberlist = memberService.queryAll();
System.out.println(memberlist.size());
return "listall";
}
3、service:queryAll()函数代码
public List<Member> queryAll() {
con = DBConnection.getConnection();
List<Member> list = null;
String sql = "select * from member where user_id = ? order by id desc";
try {
user_id=getUserId();// 当前登录用户编号
System.out.println("当前登录的用户编号为:"+user_id);
// 执行SQL语句
pt = con.prepareStatement(sql);
pt.setInt(1, user_id);
rs = pt.executeQuery();
System.out.println(sql);
// 将查询结果存入
list = this.addInList(rs);
// 关闭数据库
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBConnection.closeRs(rs);
DBConnection.closePt(pt);
DBConnection.closeCon(con);
}
// 返回list结果
return list;
}
4、错误信息:
严重: Exception occurred during processing request: null
java.lang.NullPointerException
at com.property.action.MemberAction.showall(MemberAction.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
求大神指教,到底哪里出错了?