1. 完全解耦合的方式
* 如果使用该种方式,Struts2框架中提供了一个类,ActionContext类,该类中提供一些方法,通过方 法获取Servlet的API
* 一些常用的方法如下:
1.getParameters() -- 获取请求参数,相当于request.getParameterMap();
2.getSession() -- 获取的代表session域的Map集合,就相当于操作session域。
3.getApplication() -- 获取代表application域的Map集合
大致使用方法
2.使用接口注入的方式
* Struts2框架中提供了一些接口,编写的Action类可以是去实现这些接口,然后实现这些接口中的方法,这些方法都是把一些Servlet的常用对象通过参数的方式传递进来。
* 常用的接口如下:
* ServletRequestAware -- 注入request
* ServletContextAware -- 注入ServletContext
* ServletResponseAware -- 注入response.
3.使用ServletActionContext中静态方法直接访问Servlet的API
* Struts2框架提供了一个类,ServletActionContext,该类中提供了一些静态的方法
* 具体的方法如下
* getPageContext();
* getRequest()
* getResponse();
* getServletContext();