src/main/java/codeu/controller/ProfileServlet.java
/** doGet function will eventually output HTML directly from servlet */
doGet function will eventually output HTML directly from servlet
doGet function will eventually output HTML directly from servlet
@Override
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {
    String requestUrl = request.getRequestURI();
    String username = requestUrl.substring("/user/".length());
    User user = userStore.getUser(username);
    Profile profile = profileStore.getProfile(username);
    if (profile == null) {
      System.out.println("Profile was null: " + username);
      response.sendRedirect("/index.jsp");
      return;
    }
    List<Message> messages = messageStore.getUserMessages(user.getId());
    request.setAttribute("profileUser", user);
    request.setAttribute("username", username);
    request.setAttribute("profile", profile);
    request.setAttribute("about", profile.getAbout());
    request.setAttribute("messages", messages);
    request.setAttribute("photo", profile.getPictureURL());
    request.getRequestDispatcher("/WEB-INF/view/profile.jsp").forward(request, response);
  }
@ Override public void doGet ( HttpServletRequest request , HttpServletResponse response ) throws IOException , ServletException { String requestUrl = request . getRequestURI ( ) ; String username = requestUrl . substring ( "/user/" . length ( ) ) ; User user = userStore . getUser ( username ) ; Profile profile = profileStore . getProfile ( username ) ; if ( profile == null ) { System . out . println ( "Profile was null: " + username ) ; response . sendRedirect ( "/index.jsp" ) ; return ; } List < Message > messages = messageStore . getUserMessages ( user . getId ( ) ) ; request . setAttribute ( "profileUser" , user ) ; request . setAttribute ( "username" , username ) ; request . setAttribute ( "profile" , profile ) ; request . setAttribute ( "about" , profile . getAbout ( ) ) ; request . setAttribute ( "messages" , messages ) ; request . setAttribute ( "photo" , profile . getPictureURL ( ) ) ; request . getRequestDispatcher ( "/WEB-INF/view/profile.jsp" ) . forward ( request , response ) ; }
doGet function will eventually output HTML directly from servlet
doGet function will eventually output HTML directly from servlet
// couldn't find profile, redirect to homepage