2、Struts中接收、传递数据

1、Struts2对HttpServletRequest、HttpSession和Servlet进行了封装,构造了三个Map对象来代替这三种对象。直接用相应的Map对象来保存和读取数据

方法一
1、通过ActionContext来获取request、session、application对象
Action传递数据给JSP
ActionContext context=ActionContext.getContext();
Map request=(Map)context.get(“request”);
Map session=(Map)context.getSession();
Map application=(Map)context.getApplication();
request.put(“name”,getName());

2、在jsp中读取
s e s s i o n S c o p e . n a m e {requestScope.name}
${applicationScope.name}

方法二
直接用ActionContext类的put方法
Action类页面:
ActionContext.getContext.put(“name”,getName( ));

jsp页面:
${requestScope.name} 或<%=request.getAttribute(“name’)%>

猜你喜欢

转载自blog.csdn.net/nba_linshuhao/article/details/82629186