标签:int res hone pre cep boolean use exception over
/** * 自定义异常类 */ public class TestException extends Exception { private String message; public TestException(String message) { this.message = message; } @Override public String getMessage() { return this.message; } }
/**
* 验证用户信息
*/
@Override
public boolean verify() throws TestException {
String err_msg = "";
isOk = false;
//验证用户名、密码、手机、邮箱是否为空或者空字符串
if (getUsername() == null || getUsername().equals(""))
err_msg = "用户名不能为空";
else if (getPassword() == null || getPassword().equals(""))
err_msg = "密码不能为空";
else if (getPhone() == null || getPhone().equals(""))
err_msg = "手机不能为空";
else if (getEmail() == null || getEmail().equals(""))
err_msg = "邮箱不能为空";
//判断异常字符是否为空
if (!err_msg.equals("")) {
isOk = false;
throw new TestException(err_msg);
}
return isOk;
}
//获取输出流对象
PrintWriter out = resp.getWriter();
boolean isOk = false;
try {
isOk = uc.getResult();
if (isOk) {
UserContextService usc = new UserContextService(1);
usc.getResult(ub);
if (usc.isOk() == true) {
out.println("注册成功");
}
} else {
out.println("注册失败");
}
} catch (TestException e) {
out.println(e.getMessage());
}
标签:int res hone pre cep boolean use exception over
原文地址:https://www.cnblogs.com/fatRabbit-/p/10163719.html