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

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的多翻页处理问题。包含拦截器。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值