2015-02-23 129 views
1

我希望當我登錄時,我的模型中的值(userProfile)從我的控制器傳遞到我的查看頁面,以顯示或打印用戶的電子郵件。 下面是我的視圖和控制器:從控制器傳遞值來查看頁面

我的視圖頁:

<c:out value="${userprofile.email}" /> 

控制器是:

@RequestMapping(value = "/authenticate", method = RequestMethod.POST) 
    public String authenticateLogin(@Valid @ModelAttribute("loginAttribute") UserProfileForm userProfile,         HttpServletRequest request, 
Model model){ 


    if(userProfile.getEmail() !=null && userProfile.getPassword() !=null){ 
     if(userProfileBo.processLoginCredentials(userProfile.getEmail(), userProfile.getPassword())){ 
      model.addAttribute("userProfile", userProfile.getEmail()); 
      System.out.println("Email for username is: " + userProfile.getEmail());    
      return "redirect:/treepage"; 
     } 
     else{ 
      return "redirect:/"; 
     }   

    } 
    else{ 
      return "redirect:/";  
    } 

} 

所顯示的結果是這樣的 - ${userprofile.email}

回答

0

我不喜歡MVC並且只使用它來完成一個項目,所以我的知識是有限的。我認爲在客戶端有一個ViewBag變量,您可以使用控制器中的值填充值,並從視圖中訪問它們。

0

我認爲您的代碼有一個錯誤: 您在您的控制器中設置了userProfile,並在您的視圖中使用userprofile

嘗試在您的視圖中使用<c:out value="${userProfile.email}" />,如果問題得不到解決,使用這樣的:

<h1>${userProfile.email}</h1> 
相關問題