百度广告
身份验证时,我们常常要返回一个User对象,然而又要知道到底是什么地方错误。我们可以用Exception进行控制!下面是我写的一个例子,你可以加上数据库连接!
public User validate(String userName,String password) throws InvalidNameException,WrongPasswordException{
if(password.equals("java")){
}else{
}
throw new InvalidNameException();
//return null;
public static void main(String args){
User user=null;
user=l.validate("javac","java");
System.out.println("The username is invalid!");
System.out.println("The password is wrong");
if(!(user==null)){
}
}
private String userName;
this.userName=userName;
public void setUserName(String userName){
}
return userName;
}
public InvalidNameException(){
}
public WrongPasswordException(){
点击加载更多评论>>