Struts(八)Strits2访问servlet API

1.获得servlet API的两种方法

(1).ServletActionContext类(基本都是静态方法)

public static HttpServletRequet getRequest()  //获得request
public static HttpservletResponse getResponse()  //获得response

(2).ActionContext

ActionContext actionContext = ActionContext.getContext();

Map(String,Object) map = actionContext.getSession();  获得底层的信息

 

2.服务器端代码的单元测试有两种模式:

1)容器内测试(jetty)

2)Mock测试(继承 HttpServletRequest、HttpSession、HttpServletResponse等Servlet API)。

 

3.Interface Preparable (void prepare()方法)

Preparable接口的作用是让Action完成一些初始工作,这些初始化工作是放在Preparable接口的prepare方法中完成的,该方法会在execute方法执行之前得到调用。

 

http://www.cnblogs.com/liunanjava/p/4376188.html

posted on 2015-11-07 00:18  彩屏黑白  阅读(149)  评论(0编辑  收藏  举报

导航