1. 程式人生 > >2、Struts中接收、傳遞資料

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中讀取 sessionScope.name{requestScope.name} ${applicationScope.name}

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

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