您的位置:首页 > 编程语言 > Java开发

告诉你一个真实的Struts2--(注:太注重细节的看不懂)

2009-02-14 13:42 369 查看
Struts2相对Struts1来说,简化了不少。

主要表现在以下两个方面:

1、Stuts2的API完全屏蔽了Servlet的复杂性,开发人员无需知道Servlet就可实现业务功能。

2、Struts2缺少了Struts1里的ActionForm, 它将这部分整合进了Action。降低了对开发人员的要求。

但是呢,要使用Struts2做出可维护性比较高的系统,要求开发人员对Java的面向对象具备比较深的理解。

另外,Struts2引入了拦截器这个概念。在英文文档里(Apache Struts 2 Documentation Interceptors)它是这样描述的:

Interceptors can execute code before and after an Action is invoked. Most of the framework's core functionality is implemented as Interceptors. Features like double-submit guards, type conversion, object population, validation, file upload, page preparation, and more, are all implemented with the help of Interceptors. Each and every Interceptor is pluggable, so you can decide exactly which features an Action needs to support.

Interceptors can be configured on a per-action basis. Your own custom Interceptors can be mixed-and-matched with the Interceptors bundled with the framework. Interceptors "set the stage" for the Action classes, doing much of the "heavy lifting" before the Action executes.

从上面的文档看出,拦截器并没有实际明确的概念定义。依据本人的理解,拦截器是这样的:

1、首先是Struts2里定义的一个应用接口。

2、其次,拦截器其实就是web规范里的Filter。只不过Struts2对其进行了高层抽象封装。

根据本人最近开发项目的经验,Struts2其实和Struts1是一样的。理由如下:

1、从软件的延续性方面出发,Apache开发组织在某种程度上沿袭了Struts1的设计原理。因为为了鼓励Struts1的用户继续使用Struts2。

2、另外从技术层面来说,Struts2和Struts1在很大程度上具有对应性。

ActionSupport ---> Action

Action里的数据模型--->ActionForm

Struts.xml --->Struts-config.xml

3、最核心的对应都是基于一个配置文件定义处理结果和页面的跳转关系,来完成整个业务系统的功能。

但是,要想做好Struts2的高级开发,必须了解Struts2的核心内容。这些包括:

1、OGNL

2、ActionStack

3、Interceptor

鄙人用了不到两星期学会Struts2,并且设计了一套基础类。然后用了两天时间来优化Displaytag的多翻页处理问题。包含拦截器。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐