struts框架学习二 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");

jsp界面
${a}
${b}
${c}

或则request.getAttribute("a");
session.getAttribute("b);
application.getAttribute("c");

 

上一篇:详解桶排序以及排序内容大总结


下一篇:数组中的第K个最大元素(来源力扣)(快速排序、堆排序)