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对象。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值