NOTE:Struts2

来源:互联网 发布:淘宝网-微淘 编辑:程序博客网 时间:2024/06/01 20:45

2009-3-28

 

<filter>

<filter-name>struts2</filter-name> ANNOTATION 1

<filterclass>

org.apache.struts2.dispatcher.FilterDispatcher</filterclass>

<init-param> ANNOTATION 2

<param-name>actionPackages</param-name>

<param-value>manning</param-value>

</init-param>

</filter>

 

(annotation) <#1”The FilterDispatcher: Struts 2 Begins Here”>

过滤struts2截所有http求,所以struts正是通过这过滤器来完成充当controller角色的。

The actionPackages parameter is

necessary if you are going to use annotations in your application.

actionPackages参数,是非常重要的,它告程序去什地方找注解(action的)。

 

2009-3-28

 

struts2ActionData Transfer Object问题

struts1中,Action只会有一个例,因此Action是不能作DTO的,但是在struts2中,这种情况已完全不同了,次有Struts都会重新建一个新的Action例。因此struts2中的Action都有天生就可以是一个DTO

 

default namespace

Note that the default namespace is actually the empty string "".

package声明中,往往都承一个默包,个默包的namespace就是一个空串“”。

也可以看到,其一个packagenamespace,就是URL介于于servlet 上下文与一个Action名称之的部分。如:

 

 

Package namespace是很必要的机制,基本上就像是代码的包一样,用来合理地组织action用的。更为重要的是我们常常会基于package namespace来进行权限配制。

注意:packagenamespace不是jsp的组织结构!

关于package和namespace

package和namespace不一定非得是一一对应的关系,一个namespace是可以对应多个package的!

Note that you can give the same
namespace to more than one package. If you do this, the actions from the two packages
map to the same namespace. This isn’t necessarily a problem. You might choose
to separate your actions into separate packages for some functional reason that
doesn’t warrant a distinct namespace.

通常来说:namespace的组织原则是:依据action的相关性.其实默认情况下,一个action的namespace就是这个action类的包路径,这也体现了namespace的基本作用.就像我们按功能相关性来组织jsp一样,action的组织最好是用功能相关性来组织,有可能话也许会和jsp的组织结构能够对应起来.如果namespace是按功能来划分的,那么,对于其内部的action来说,如果它们需要有不同的配置,那就分成多个package,但是namespace是一样的.

 

2009-4-1

 

          关于Action的执行机理:

Struts2中一个Action的执行过程被 封闭在一个ActionInvoction中。下图是对一个Action的执行过程的详细描述。这个过程基本就是将拦截器栈中的拦截器依次读出并执行,最后执行Action。同样,在执行完毕返回的过程中也会依次调用这些拦截器。基本上这些拦截器就是负责一些横切性质的工作。也就是一些 preprocesspostprocess.

 

 

2009-4-11

 

关于Strutsspring集成的问题:

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener

</listener-class>

</listener>

At this point, you’re completely ready to start managing your objects with Spring. But,

as we indicated earlier, Spring won’t just start handling all of your objects. You must

tell Spring to intervene. To have Spring manage your objects, you need to declare

these objects as Spring beans in a Spring configuration file. By default, the Spring

container created by the ContextLoaderListener looks for metadata in an XML file at

/WEB-INF/applicationContext.xml.

 

以上是web.xml中一个listener的注册。正是这个listenerspring开始读取配件文件,并开始创建bean,而这个配件文件在哪呢?默认的位置就是/WEB-INF/applicationContext.xml

当然,我们也可以指定文件位置,方法如下:

 

<!-- Context Configuration locations for Spring XML files -->

    <context-param>

        <param-name>contextConfigLocation</param-name>

        <param-value>

            classpath:/applicationContext-resources.xml

            classpath:/applicationContext-dao.xml

            classpath:/applicationContext-service.xml

            classpath*:/applicationContext.xml

            /WEB-INF/applicationContext*.xml

            /WEB-INF/xfire-servlet.xml

            /WEB-INF/security.xml

        </param-value>

    </context-param>

 

2009-5-15

 

while actions that don’t define any interceptor-refs themselves will inherit the default

interceptors, as soon as an action declares its own interceptors, it loses that automatic

default and must explicitly name the defaultStack in order to use it.

 

 

Struts2actionUrl的数据绑定。

Struts2采用了JavaBean的风格——要访问数据的话,就给字段提供一个gettersetter,要访问请求字符串和表单也是一样的道理。每一个请求字符串和表单的值都是一个简单的名/值对,所以要设定一个特定名称的值的话,就要为它提供一个setter。比如,如果一个JSP调用了/home.action?framework=struts&version=2这样一个请求,那么action就应该提供如下两个settersetFramework( String frameworkName )setVersion( int version )

原创粉丝点击