beginJsp2.0外文书籍源代码
源代码在线查看: user4.java
package com.wrox.except;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
public class User4
{
static Logger logger = Logger.getLogger("com.wrox.except.User");
private String username;
private String password;
static
{
PropertyConfigurator.configure("C:\\java\\tomcat50\\webapps"
+ "\\Exceptions\\WEB-INF\\config.properties");
}
public User4()
{
}
public void setUsername(String username)
{
logger.debug("Username set: " + username);
this.username = username;
}
public String getUsername()
{
return this.username;
}
public void setPassword(String password)
{
this.password = password;
}
public void validate() throws UserException, Exception
{
if(this.username == null)
{
throw new UserException("UserName must be supplied !!");
}
if(this.password == null)
{
logger.error("Password is null for " + username);
throw new UserException("Password must be supplied !!",
this.username);
}
if (!(this.username.equals("Dougal")
&& this.password.equals("roundabout")))
{
Exception trouble = new Exception("Couldn't validate your"
+ " password!");
throw trouble;
}
logger.info("Validation successful for: " + this.username);
}
}