@Override public String execute(HttpServletRequest request, HttpServletResponse response) { String articleContent = request.getParameter("contentInputArea"); String articleTitle = request.getParameter("title"); System.out.println("Article title: " + articleTitle); System.out.println("Article content: " + articleContent); ArticleDao articleDao = new ArticleDao(); SimpleDateFormat date = new SimpleDateFormat("yyyy/MM/dd HH:mm"); User currentUser = UserService.UserManager.getCurrentUser(); try { System.out.println(request.getRemoteUser()); articleDao.addArticle( new Article(articleTitle, articleContent, date.format(new Date())), currentUser); } catch (DaoException e) { e.printStackTrace(); return "/errorPage.jsp"; } return "/loginSuccess.jsp"; }
@Override public String execute(HttpServletRequest request, HttpServletResponse response) { UserService userService = new UserService(); User user = new User( request.getParameter("firstname"), request.getParameter("lastname"), request.getParameter("username"), request.getParameter("password"), UserAccessPriveledge.MEMBER); try { userService.createUserAccount(user); return "/loginPage.jsp"; } catch (DaoException e) { e.printStackTrace(); return "/error.jsp"; } catch (InvalidUserException e) { e.printStackTrace(); System.out.println("Invalid user."); // TODO: Correct error message as to what was invalid. return "/error.jsp"; } }