ActionContext.getContext().getSession() 和 HttpSession session = ctx.getSession(); 中session的區別

① Map session = ServletActionContext.getContext().getSession(); 

②                          ActionContext.getContext().getSession(); 

③ WebContext ctx = WebContextFactory.get();
     HttpSession session = ctx.getSession();


① 獲取的session是原生的session,可以調用setAttribute()方法

② 獲取的session是struts封裝過的一個Map類型的session,只能調用put()方法緩存數據。

②和③前一個是將值保存到session中,效果等同於session.setAttribute("",""),

     前者就是struts2對後者的一個封裝,把session,request,application全都放到了actioncontext()容器中了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章