struts2框架学习二 action对jsp传值

action

HttpServletRequest、HttpSession和ServletContext

Struts2对这个三个对象用Map进行了封装,我们就可以使用Map对象来存取数据了。

ActionContext actionContext = ActionContext.getContext();

//get HttpServletRequest
            Map<String,Object> request = (Map) actionContext.get("request");
            request.put("a", "a is in request");
                    
            //get HttpSession
            //Map<String,Object> session = (Map) actionContext.get("session");
            Map<String,Object> session = actionContext.getSession();
            session.put("b", "b is in session");
                    
            //get ServletContext
            //Map<String,Object> application  = (Map) actionContext.get("application");
            Map<String,Object> application  = actionContext.getApplication();
            application.put("c", "c is in application");
//直接使用ActionContex类的put()方法

        ActionContext.getContext().put("book", book);
jsp界面
${a}
${b}
${c}
${book}
或则request.getAttribute("a");
session.getAttribute("b);
application.getAttribute("c");
request.getAttribute("book");

 

posted @ 2020-04-03 15:46  张利杰j  阅读(153)  评论(0编辑  收藏  举报