Learning two struts framework for action by value jsp

action

HttpServletRequest、HttpSession和ServletContext

Struts2 this package with three Map object, we can use the Map object to access the data.

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");

 

Guess you like

Origin www.cnblogs.com/zlj843767688/p/12626906.html