标签:
1、Properites 加载配置文件 web路径设置
2、CommonUtils.uuid()
3 、TxQueryRunner c3p0数据库连接池
4、MailUtil (邮箱的smtp服务要打开 否则 fail connected)
5、MessageFormat 完成对占位符的替换
6、将表单数据封装到user对象中 User formUser = CommonUtils.toBean(req.getParameterMap(), User.class);
7、alt+shit+s 弹出菜单
8、自定义异常 在UserService层抛出 UserServlet层捕获异常 并且设置request域 转发到msg.jsp页面
1 UserService 2 3 try { 4 User user = userDao.findByCode(code); 5 if (user == null) 6 throw new UserException("无效的激活码"); 7 if (user.isStatus()) 8 throw new UserException("您已经激活过了,不能二次激活!"); 9 userDao.updateStatus(user.getUid(), true); 10 } catch (SQLException e) { 11 // TODO Auto-generated catch block 12 throw new RuntimeException(e); 13 }
1 UserServlet 2 // 激活功能 3 public String activation(HttpServletRequest req, HttpServletResponse resp) { 4 //System.out.println("activation"); 5 //1、获取激活码 6 //2、交给service 的 activation功能来激活 7 //service方法可能跑出异常 把异常信息拿来保存到request中 8 //转发到msg.jsp显示 9 String code=req.getParameter("activationCode"); 10 try { 11 userService.activation(code); 12 req.setAttribute("code", "success"); 13 req.setAttribute("msg", "恭喜激活成功,请马上登录!"); 14 } catch (UserException e) { 15 req.setAttribute("msg", e.getMessage()); 16 req.setAttribute("code", "error"); 17 18 } 19 return "f:/jsps/msg.jsp"; 20 }
9、关于将sqlException IoException 转化为 new RuntimeException(e)的事。
标签:
原文地址:http://www.cnblogs.com/xiaoying1245970347/p/4767865.html