-
OGNL
1.1 OGNL的全称是Object Graph Navigation Language(对象图导航语言),它是一种强大的表达式语言
1.2 OgnlContext(ongl上下文)其实就是Map<String,Object>
OgnlContext=根对象(1)+非根对象(N)
非根对象要通过"#key"访问,根对象可以省略"#key"注1:context:英文原意上下文,环境/容器
1.3 把根对象和非根对象说出来 -
ValueStack
2.1 值栈
先进后出的数据结构,弹夹 push/pop
2.2 为什么要使用ValueStack作为根对象
放到值栈中的对象都可视为根对象
employ
manager name
student name
for(String s:ctx){
if(name){
break;
}
}
ctx.put(“employ”,employ);---------2
ctx.put(“manager”,manager);------1
ctx.put(“student”,student)---------0
从小到大
page -> request -> session -> application
从上至下
A
B
C
D
//struts2的工作流程
//伪代码
*.action
3. ActionContext
3.1 ActionContext ac = ActionContext.getContext();//保证同一请求中只创建一个上下文
request
session
application
parameters
ValueStack(root)
3.2 向ValueStack压栈
ValueStack vs = ac.getValueStack();
vs.push(XxxAction)//studentAction
vs.push(ModelDirver.getModel())//model不为null student
3.3 Map<String,String[]> map = request.getParamterMap();
//参数名==OGNL表达式
{“userName”:“zs”,“sid”:18,“sex”:“F”}
setValue("userName", ac, vs, "zzz");
setValue("uname", ac, vs, "kfc");
setValue("upwd", ac, vs, "999");
setValue("age", ac, vs, "17");
student [0]
studentAction [1]
- struts2中传递数据
可以使用作用域,但更多的是利用ValueStack或ActionContext(ognl)
这里插入图片描述