`
dowhathowtodo
  • 浏览: 771107 次
文章分类
社区版块
存档分类
最新评论

struts2知识点

 
阅读更多

Struts2知识点总结:

1、 struts2的体系结构:充当中央控制器的核心过滤器FilterDispather、充当线程清洁工的ActionContextCleanup、决定是否调用自定义业务控制器Action的action映射器、根据配置文件创建Action执行环境的Action代理、action执行环境包括struts2标签库在内的struts2视图组建。

ActionContextCleanup过滤器是struts2的一个常用辅助类,主要用于处理清除当前线程的ActionContext和dispather,防止内存泄露。在web.xml中配置

<filter>

<filter-name>struts2-cleanup</filter-name>

<filter-class>org.apache.struts2.dispatcher.ActionContextCleanup</filter-class>

</filter>

<filter-mapping>

<filter-name>struts2-cleanup</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

核心控制器FilterDispatcher是struts2框架的基础,包涵了框架内部的控制流程和处理机制。

FilterDispatcher在web.xml中的配置代码如下

<filter>

<filter-name>struts2</filter-name>

<filter-class>org.apache.struts2.dispatcher.FilterDispatecher</filter-class>

</filter>

<filter-mapping>

<filter-name>struts2</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

2、 struts2常用类介绍

Action接口:通过实现接口Action可以快速的开发业务控制器Action类,具体的业务逻辑在execute()方法中编写,调用ActionContext.getContext()可取得ServletContext的引用,进而取得HttpServletRequest及httpsession对象的访问。为规范Action处理结果的result的命名,Action接口定义了5个常用的字符串常量:success、none、error、input、login

ActionSupport类实现类Action接口和Validate接口,因此通过继承该类也可以简化业务逻辑控制器Action的开发,具体的业务逻辑放在execute中执行,数据验证则放在validate方法中。

ActionContext类:是struts2访问ServletApi(HpptServletRequest、httpsession、servletcontext)提供的工具类,同时也是struts2中的默认Action类。

方法:getObject(key)得到HttpServletRequest对象中的指定属性

getContext()返回绑定到当前线程特定的ActionContext

getParameters() 得到所请求的参数;

getSession()得到一个HttpSession的模拟对象

getApplication()得到一个ServletContext的模拟对象

ServletActionContext类:struts2为直接访问ServletApi提供的工具类。

getPageContext()得到当前web应用中的pagecontext对象;

getRequest()得到当前web应用中的httpservletrequest对象

getresponse()得到当前web应用中HttpservletResponse对象

getServletContext()得到当前web应用中的ServletContext对象。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics