Servlet 报错 java.lang.NullPointerException
一个由Tomcat部署的数据库Web程序
代码是老师提供的,同学用eclipse跑起来都正常,但是我用IDEA出问题了。
下面的表单POST之后,就报错
java.lang.NullPointerException
com.action.library.LoginAction.memberLogin(LoginAction.java:12)
com.controller.library.LoginServlet.service(LoginServlet.java:30)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
<form action="servlet/LoginServlet" method="POST">
<table>
<tr>
<td>Member Number:</td>
<td><input type="text" name="member_no"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td><input type="submit" value="提交"></td>
<td><input type="reset" value="重置"></td>
</tr>
</table>
</form>
相关的代码片段如下
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = -8052223741830167994L;
public LoginServlet() {
}
public void service(HttpServletRequest request, HttpServletResponse response) {
try {
request.setCharacterEncoding("utf-8");
} catch (UnsupportedEncodingException var10) {
var10.printStackTrace();
}
String memberNo = request.getParameter("member_no");
String password = request.getParameter("password");
LoginAction login = new LoginAction();
Member member = login.memberLogin(memberNo, password);
if (member == null) {
try {
response.sendRedirect("/library/login_incorrect.html");
} catch (IOException var9) {
var9.printStackTrace();
}
} else {
request.getSession().setAttribute("member", member);
try {
response.sendRedirect("/library/servlet/RefreshMainPageServlet");
} catch (IOException var8) {
var8.printStackTrace();
}
}
}
}
public class LoginAction {
public LoginAction() {
}
public Member memberLogin(String memberNo, String password) {
DaoManager dm = DaoManager.getInstance();
MemberDao memberDao = (MemberDao)dm.getDao(MemberDao.class);
Member member = null;
try {
dm.begin();
member = memberDao.getMemberByMemberNoAndPassword(memberNo, password);
dm.commit();
} catch (Exception var10) {
var10.printStackTrace();
} finally {
dm.end();
}
return member;
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…