Servlet.service() for servlet UserServlet threw exception
严重:Servlet.service()forservletLoginServletthrewexceptionjava.lang.NullPointerExceptio...
严重: Servlet.service() for servlet LoginServlet threw exception
java.lang.NullPointerException
at com.cn.serviceImpl.UserServiceImpl.checkUserLogin(UserServiceImpl.java:72)
at com.cn.servelt.LoginServlet.doPost(LoginServlet.java:35)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
我检查了checkUserLogin方法,不知道哪里出现空对象了,求助
public User checkUserLogin(String loginName, String loginPwd) {
User user=new User();
String sql="select userid,username,userpwd,useradmin from t_user where username = ? and userpwd = ?";
try {
this.getConnection();
ps=conn.prepareStatement(sql);
ps.setString(1,loginName);
ps.setString(2, loginPwd);
rs=ps.executeQuery();
while(rs.next()){
user=new User();
user.setUserId(rs.getInt("userid"));
user.setUserName(rs.getString("username"));
user.setUserPwd(rs.getString("userpwd"));
user.setUserAdmin(rs.getInt("useradmin"));
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
this.closeResource();
}
return user;
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String userName=request.getParameter("userName");
String userPwd=request.getParameter("passWord");
//35行 User user=userService.checkUserLogin(userName, userPwd);
HttpSession session=request.getSession();
session.setAttribute("user", user); 展开
java.lang.NullPointerException
at com.cn.serviceImpl.UserServiceImpl.checkUserLogin(UserServiceImpl.java:72)
at com.cn.servelt.LoginServlet.doPost(LoginServlet.java:35)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
我检查了checkUserLogin方法,不知道哪里出现空对象了,求助
public User checkUserLogin(String loginName, String loginPwd) {
User user=new User();
String sql="select userid,username,userpwd,useradmin from t_user where username = ? and userpwd = ?";
try {
this.getConnection();
ps=conn.prepareStatement(sql);
ps.setString(1,loginName);
ps.setString(2, loginPwd);
rs=ps.executeQuery();
while(rs.next()){
user=new User();
user.setUserId(rs.getInt("userid"));
user.setUserName(rs.getString("username"));
user.setUserPwd(rs.getString("userpwd"));
user.setUserAdmin(rs.getInt("useradmin"));
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
this.closeResource();
}
return user;
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String userName=request.getParameter("userName");
String userPwd=request.getParameter("passWord");
//35行 User user=userService.checkUserLogin(userName, userPwd);
HttpSession session=request.getSession();
session.setAttribute("user", user); 展开
展开全部
不是checkUserLogin方法的问题,
问题在于 这个72行里, userDao是null。
因此,看看你是怎么调用的,看看LoginServlet.java第35行的代码,
at com.cn.servelt.LoginServlet.doPost(LoginServlet.java:35)
如果还看不出来,就把LoginServlet.java第35行及其前后的代码贴一些上来。
问题在于 这个72行里, userDao是null。
因此,看看你是怎么调用的,看看LoginServlet.java第35行的代码,
at com.cn.servelt.LoginServlet.doPost(LoginServlet.java:35)
如果还看不出来,就把LoginServlet.java第35行及其前后的代码贴一些上来。
追问
我贴上来了,请帮我再看看吧,实在看不出来了
追答
我刚才看到你在那个72行前面有userDao的私有成员变量,不过没有初始化,应该有对应的setter/getter方法。
是不是应该在这个LoginServlet.java第35行前面,调用一下setUserDao之类的方法,不然userDao一定是null啊
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询