private static SAXException toSAXException(UserException e) throws IOException, IncorrectSchemaException { SAXException se = e.getException(); Exception cause = se.getException(); if (cause instanceof IncorrectSchemaException) throw (IncorrectSchemaException) cause; if (cause instanceof IOException) throw (IOException) cause; return se; }
public String regist(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 把表单数据封装到User对象中 final User user = CommonUtils.toBean(request.getParameterMap(), User.class); user.setUid(CommonUtils.uuid()); user.setState(false); user.setCode(CommonUtils.uuid() + CommonUtils.uuid()); // 完成注册 try { userService.regist(user); } catch (UserException e) { String msg = e.getMessage(); // 获取异常信息 request.setAttribute("msg", msg); request.setAttribute("user", user); return "/jsps/regist.jsp"; } final String url = "http://*****:*****@163.com"); mail.addToAddress(user.getEmail()); mail.setSubject("来自Jon超级图书商城的激活邮件"); mail.setContent("点击<a href='" + url + "'>这里</a>完成激活~!"); Session session = MailUtils.createSession("smtp.163.com", "*****@*****.**", ";lkj0987"); try { MailUtils.send(session, mail); } catch (Exception e) { throw new RuntimeException(e); } } }.start(); request.setAttribute("msg", "注册成功!请马上去邮箱激活,若没有立刻受到邮件,说明您网速有问题!"); List<String> links = new ArrayList<String>(); links.add("<a href='" + request.getContextPath() + "/index.jsp'>主页</a>"); links.add("<a href='" + request.getContextPath() + "/jsps/login.jsp'>登录</a>"); request.setAttribute("links", links); return "/jsps/msg.jsp"; }