`

Struts2 Annotation 注解配置

阅读更多

Struts2 Annotation 注解配置也叫Zero Configuration(零配置),它省去了写xml文件的麻烦,可以直接在类叫进行配置,不用在java文件和xml文件中来回切换。

1、Action级的注解

  @ParentPackage--父包

      该注解相当于<package name="login" extends="struts-default"></package>中的extends属性,例如@ParentPackage(value="struts-default")

  @Namespace----命名空间

     该注解相当于

<package name="login" extends="struts-default" namespace="logintest"></package>中的namespace属性,例如:@@Namespace(value="/longspace")

 @Result---转向

该注解相当于

<action name="login" class="com.lwsoft.action.LoginAction">
     <result name="success">/loginsuc.jsp</result>
 </action>中的 <result name="success">/loginsuc.jsp</result>

例如@Result(name="success",location="/loginsuc.jsp",type="redirect") !!!注意,在struts2.1.6中是location来转向页面,而在struts2.0.4是value属性

  @Results

    @Results({
         @Result(name="success",location="/usersuc.jsp"),
        @Result(name="error",location="/usererror.jsp")
  
   })来配置多个转向

 

 

以上是对struts2 注解简单的介绍,

要想在Action上使用注解,还得修web.xml文件中的一些配置

 

<filter-name>struts</filter-name>
            <filter-class>
                org.apache.struts2.dispatcher.FilterDispatcher
            </filter-class>
               <!--  //固定格式-->
                <param-name>actionPackages</param-name>
                com.struts2.action1,com.struts.action2-->
                <param-value>com.struts2.action</param-value>
              </init-param>
    </filter>
                <!--  action所在的包,如果在多个包中,用逗号隔开
            <init-param>
分享到:
评论
1 楼 青春的、脚步 2012-11-12  
jar包需要哪些

相关推荐

    Struts2之Annotation注解配置使用案例struts013

    参考博文:http://blog.csdn.net/u011638419/article/details/41743049

    struts2annotation json

    struts2,json-plugin, 并全注解零配置

    struts2注解详解

    而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行配置,甚至不需要使用Annotation进行配置,而是由struts2根据约定...

    Struts2注解使用说明文档

    而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行配置,甚至不需要使用Annotation进行配置,而是由struts2根据约定...

    struts2 interceptor annotation plugin

    用注解(annotation)方式配置struts2 (webwork) 中action的拦截器(interceptor)

    struts2 + spring 注解配置

    没分了所以就随便在网上找了个配置,如果你真的需要,可以私密我,一定可以解决你的问题,

    struts2注解使用.doc

    从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件...甚至不需要使用Annotation进行配置,而是由struts2根据约定自动配置。

    Struts2入门教程(全新完整版)

    十一、注解配置 59 十二、总结 本教程对struts2的基本知识进行了一些说明,关于struts2的更多详细内容应参看struts2的官方文档及提供的app实例。 下面对struts2的基本执行流程作一简要说明,此流程说明可以结合官方...

    基于Struts2.18+Spring2.5+Hibernater3.3+Annotation注解开发的电子商务网站demo

    无聊之秋,做了个电子商务网站demo,巩固了一下对SSH三大开源框架的认识,比且融入了Annotation减少了xml配置文件的出现,本人只是个菜鸟,希望该资源能对一些朋友略有帮助!

    Struts2.3.15 基于Annotation的小DEMO

    自己学Struts的注解,写的一个零配置小demo。 很简单很简单,只供新手学习。

    基于Maven,Struts2, Spring,Hibernate全注释的开发框架

    使用Maven3.0.5, Struts2, Spring, Hibernate3, annotation实现零配置的开发框架.里面有详细的开发指导文档, 后台用googlecode的 hibernate-generic-dao - Generic DAO 和 Search的代码,完全进行封装. 由于Generic ...

    Struts2注解

    配置web.xml,加入注解,验证注解,Convention的Annotation ,、与Result配置相关的Annotation

    ssh全注解-annotation

    struts2+hibernate+spring无配置架构

    spring+hibernate3.2+struts2.0 注解

    spring+hibernate3.2+struts2.0 注解,超级简化,省略hbm.xml、bean注入xml配置等,一切annotation

    基于注解Annotation的最新版SSH(Struts2.3.7+Hibernate4.1.9+Spring3.2.0)框架整合开发

    基于注解Annotation的最新版SSH(Struts2.3.7+Hibernate4.1.9+Spring3.2.0)整合开发,真正实现零配置。 最新版本Struts、Spring、Hibernate框架整合: struts-2.3.7 spring-framework-3.2.0.RELEASE hibernate-...

    SSH2-Annotation.rar_annotation ssh2_ssh2_ssh2 annotation

    该程序实现了零配置通过注解代替了hibernate中繁琐的hb.XML配置 使用spring 控制翻转 ,托管hibernate和struts2

    框架整合jar包及其它功能包_spring4.2.3+hibernate5.0.2+struts2.3.24

    ehcache二级缓存,c3p0连接池,文件上传,dom4j,mysql数据库驱动,jscharts图表统计图走势,JSTL,struts日历控件包,base64加密,Excel文件生成,...ehcache二级缓存配置文件,,支持annotation注解,支持xml配置等。

    Spring的学习笔记

    (一) Annotation注解方式配置事务管理 31 (二) Spring事务选项 35 (三) XML文件形式配置Spring事务管理 37 四、 HibernateTemplate 38 (一) HibernateTemplate 38 (二) HibernateDaoSupport 39 第十一课:Spring整合...

    spring2.5 学习笔记

    (一) Annotation注解方式配置事务管理 31 (二) Spring事务选项 35 (三) XML文件形式配置Spring事务管理 37 四、 HibernateTemplate 38 (一) HibernateTemplate 38 (二) HibernateDaoSupport 39 第十一课:Spring整合...

    ssh2全注解demo(sql server 2008)

    基于注解Annotation的最新版SSH(Struts2.3.7+Hibernate4.1.9+Spring3.2.0)整合开发,真正实现零配置。记得修改数据源。

Global site tag (gtag.js) - Google Analytics