获取NullPointerException并搜索所有可能的方法,但无法找到我收到此错误的原因。这是我的代码; 该错误在controllerServletSign.java行中:36 if((sign.search(m))== true)
daoSign.java
public class daoSign {
Connection connection = null;
public daoSign(){
connection = Utility.getConnection();
}
public boolean search(modelLogin m){
try {
String name = m.getName();
String password = m.getPassword();
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM user");
while (rs.next()) {
if((rs.getString("name")== name) && (rs.getString("password")== password)){
return true;
}
}
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
}
controllerServletSign.java
@WebServlet("/controllerServletSign")
public class controllerServletSign extends HttpServlet {
private static final long serialVersionUID = 1L;
daoSign sign;
modelLogin m = new modelLogin();
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
String name = request.getParameter("name");
String password = request.getParameter("passsword");
m.setName(name);
m.setPassword(password);
if((sign.search(m))== true){ //this line is giving exception
System.out.println("welcome " + name);
}
else{
System.out.println("worng");
}
}