자체 인증을 만들려고합니다. 로그인 할 때마다 사용자 이름이 GAE 데이터 저장소에 없으므로 INTERNAL_SERVER_ERROR을 (를) 갖게됩니다.GAE Datastore로 인증하면 엔터티 사용자가 null을 반환합니다.
java.lang.NullPointerException
at com.pawnsoftware.User.authenticate(User.java:16)
at com.pawnsoftware.UserLoginServlet.doPost(UserLoginServlet.java:24)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
등등 ...
방법이 오류를 피하기 않습니다
는이 있다고?
오류는 말한다 라인에 있습니다 :
if (user==null) {
message = "Username not found.";
}
인증하고 사용자 :
public static String authenticate(String username, String password) {
String message;
Entity user = UserUtil.findUserEntity(username);
String pass = user.getProperty("password").toString();
if (user==null) {
message = "Username not found.";
} else if (user!=null && !password.equals(pass)) {
message = "Password is incorrect.";
} else if (user!=null && password.equals(pass)) {
message = "Successfully logged in!";
} else {
message = "Sorry, cannot find the username and password.";
}
return message;
}
사용자 찾기 엔티티 :
: 인증에public static Entity findUserEntity (String username) {
Key userKey = KeyFactory.createKey("User", username);
try {
return datastore.get(userKey);
} catch (EntityNotFoundException e) {
return null;
}
}
업데이트 사용이 null의 경우 16,
public static String authenticate(String username, String password) { String message; Entity user = UserUtil.findUserEntity(username); password = encrypt(password); String pass = ""; try { pass = user.getProperty("password").toString(); } catch (NullPointerException e) { message = "Username not found."; } if (user==null) { message = "Username not found."; } else if (user!=null && !password.equals(pass)) { message = "Password is incorrect."; } else if (user!=null && password.equals(pass)) { message = "Successfully logged in!"; } else { message = "Sorry, cannot find the username and password."; } return message; }
NullPointerException 정보 주셔서 감사. –