Struts2中的Action獲取JSP常用內置對象

常用的jsp內置對象:request,response,session,application
1.解耦合
局部變量
session: ActionContext.getContext().getSession();
request: ActionContext.getContext().get("request"); (Map<String,Object>接收)
application: ActionContext.getContext().getApplication();
成員變量
session: 實現SessionAware接口
request: 實現RequestAware接口
application: 實現ApplicationAware接口

2.耦合
局部變量
session: ServletActionContext.getRequest().getSession();
request: ServletActionContext.getRequest();
response: ServletActionContext.getResponse();
application: ServletContext application=ServletActionContext.getServletContext();
成員變量
session: 實現ServletRequestAware接口,通過request.getSession()來取到
request: 實現ServletRequestAware接口
response: 實現ServletResponseAware接口
application: 實現ServletApplicationAware接口
發佈了36 篇原創文章 · 獲贊 4 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章