struts2 知识梳理

写此文章时,最新struts2版本:2.3.6

一:struts.xml配置详解:

1.<include> 表示引入其他配置文件

2.<constant> 定义常量

3.<package>:   

属性 是否必需 描述
name 是 包名,作为其它包应用本包的标记
extends 否 设置本包继承其它包
namespace 否 设置包的命名空间,会改变url,
abstact 否 设置为抽象包

4<action>和<result> 

<action>有name,class,method,converter.四个属性值.method默认,则默认执行action的execute方法

<result>配置对应的视图文件,jsp等. result的type有"freemaker,dispatcher(jsp,html),redirect"等.

action中要通配符使用.

5.<exception-mapping>和<global-exception-mapping>

配置异常时对应的视图信息,前者是Action范围,后者是包范围.

6.default-class-ref , default-action-ref,default-interceptor-ref:

  当没有为action指定class时,系统自动用default-class-ref配置指定的类.

  当请求的action不存在时,系统会抛出404,可以用default-action-ref来指定默认的action,会更加友好

  default-interceptor-ref用来设置整个包范围所有Action所要应用的默认拦截器信息.

7 <interceptors>(<interceptor>或者<interceptor-stack>)

  使用此标签向struts2框架中注册拦截器或者拦截器栈.

8.interceptor:

  通过该标签为所在的action添加拦截器功能.拦截器类似于servlet的过滤器或者java的proxy一样,提供预处理和事后处理.

9 global-results:

  通过此标签统一配置这些物理视图所对应的逻辑视图. 

二:struts的好处?

参考:

http://struts.apache.org/ struts2官网.

http://struts.apache.org/release/2.3.x/docs/home.html  参考文档.2.3.x ,也可参考下载的struts中的docs目录下.

http://struts.apache.org/release/2.3.x/docs/guides.html  guides

http://www.dzone.com/tutorials/java/struts-2/struts-2-tutorial/struts-2-tutorial.html 教程例子

未完待续,欢迎大家补充和指正...

原文地址:https://www.cnblogs.com/waniu/p/3804587.html