struts2如何跟servlet的api进行交互?
ServletActionContext这个是比较常用的一种api
ServletActionContext这个是比较常用的一种api
ActionContext: The ActionContext is thread local which means that values stored in the ActionContext are unique per thread,表明他是线程安全的.注意一点,他的getsession返回来的是一个map,他为什么提供这样的一个东西,主要是为了单元测试.web应用必须要有容器才行,而有了这个那就可以用单元测试框架进行测试了.
服务器端代码的单元测试有两种模式:
1) 容器内测试(Jetty)
2) Mock测试(继承HttpServletRequest、HttpSession、HttpServletResponse等Servlet API)。
关于Preparable接口:他位于xwork包下面
Preparable接口的作用是让Action完成一些初始化工作,这些初始化工作是放在Preparable接口的prepare方法中完成的,该方法会在execute方法执行之前得到调用。