2011-01-27 118 views
1

你好我收到以下錯誤[不能因爲同名的現有模型對象的暴露會話屬性「用戶」]錯誤與春季會議

javax.servlet.ServletException: Cannot expose session attribute 'user' because of an existing model object of the same name 
    org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel(AbstractTemplateView.java:141) 
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250) 

代碼

@Controller 
@RequestMapping("/admin") 
@SessionAttributes("user") 
public class AdminHome {  
    @RequestMapping("home") 
    public String homePage(HttpSession session, ModelMap map) { 
     map.addAttribute(org.brahmaa.ads.util.impl.UserInfo.getPrincipal(session)); 
     return "admin/home"; 
    } 
} 
+0

這是什麼時候發生的?這是全班上課嗎? – Bozho 2011-01-27 08:46:45

+0

它發生在我訪問/ admin /主頁時。是的,它是整個班級。 – nidhin 2011-01-27 09:21:33

回答

1

至於據我所知,map.addAttribute(org.brahmaa.ads.util.impl.UserInfo.getPrincipal(session));從會話中提取user屬性並將其放入模型中。 @SessionAttriubtes指示Spring自動執行相同操作。所以他們衝突。您只能使用其中一種方法,而不能同時使用這兩種方法。

3

我突然也得到了這個例外。原來我已經添加了這個Freemarker屬性:

<property name="exposeSessionAttributes" value="true"/>