严重: Servlet.service() for servlet UserServlet threw exception
java.lang.NullPointerExceptionatcom.dao.UserDAO.login(UserDAO.java:24)atcom.action.Us...
java.lang.NullPointerException
at com.dao.UserDAO.login(UserDAO.java:24)
at com.action.UserServlet.login(UserServlet.java:49)
at com.action.UserServlet.doPost(UserServlet.java:38)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
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:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
这是错误
下面是UserDAO.java
package com.dao;
import com.model.UserForm;
import com.tools.ConnDB;
import java.sql.*;
public class UserDAO {
private ConnDB conn;
public UserDAO() {
conn = new ConnDB();
}
//验证用户的方法,返回为1表示登录成功,否则表示登录失败
public int login(UserForm m){
int flag=0;
String sql = "SELECT * FROM tb_user where userName='" +
m.getUserName() + "'";
try {
ResultSet rs = conn.executeQuery(sql);
if (rs.next()) {
String pwd = m.getPwd();
System.out.println("密码:"+pwd);
if (pwd.equals(rs.getString(3))) {
flag = 1;
rs.last();
int rowSum = rs.getRow();
rs.first();
if (rowSum != 1) {
flag = 0;
System.out.print("获取的row的值:" + sql + rowSum);
}
} else {
flag = 0;
}
}else{
flag = 0;
}
} catch (SQLException ex) {
flag = 0;
}
return flag;
}
}
哪个大神救救我 展开
at com.dao.UserDAO.login(UserDAO.java:24)
at com.action.UserServlet.login(UserServlet.java:49)
at com.action.UserServlet.doPost(UserServlet.java:38)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
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:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
这是错误
下面是UserDAO.java
package com.dao;
import com.model.UserForm;
import com.tools.ConnDB;
import java.sql.*;
public class UserDAO {
private ConnDB conn;
public UserDAO() {
conn = new ConnDB();
}
//验证用户的方法,返回为1表示登录成功,否则表示登录失败
public int login(UserForm m){
int flag=0;
String sql = "SELECT * FROM tb_user where userName='" +
m.getUserName() + "'";
try {
ResultSet rs = conn.executeQuery(sql);
if (rs.next()) {
String pwd = m.getPwd();
System.out.println("密码:"+pwd);
if (pwd.equals(rs.getString(3))) {
flag = 1;
rs.last();
int rowSum = rs.getRow();
rs.first();
if (rowSum != 1) {
flag = 0;
System.out.print("获取的row的值:" + sql + rowSum);
}
} else {
flag = 0;
}
}else{
flag = 0;
}
} catch (SQLException ex) {
flag = 0;
}
return flag;
}
}
哪个大神救救我 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询