struts框架使用

获取key的几种方式:

//1.得到ActionContext对象
ActionContext context = ActionContext.getContext();//这是从当前线程的局部变量中获取引用
//2.往map中存入数据
context.put("contextMap","hello contextMap");//把数据直接存到了大Map中

//往session中存数据
//第一种方式:获取key为session的map
Map<String,Object> sessionAttribute = context.getSession();//得到key值为session的小map
sessionAttribute.put("sessionMap","hello sessionMap");
//第二中方式:直接使用原始的HttpSession对象
HttpSession session = ServletActionContext.getRequest().getSession();
session.setAttribute("sessionMap1","hello sessionMap1");

其他作用域类同。

猜你喜欢

转载自blog.csdn.net/weixin_43520099/article/details/106743747
今日推荐