Struts2 Annotation 註解配置

來源:互聯網
上載者:User
Struts2 Annotation 註解配置
Struts2 Annotation 註解配置也叫Zero Configuration(零配置),它省去了寫xml檔案的麻煩,可以直接在類叫進行配置,不用在java檔案和xml檔案中來回切換。
1、Action級的註解
@ParentPackage--父包
該註解相當於中的extends屬性,例如:@ParentPackage(value="struts-default")
@Namespace----命名空間
該註解相當於

中的namespace屬性,例如:@@Namespace(value="/longspace")
@Result---轉向
該註解相當於
/loginsuc.jsp中的 /loginsuc.jsp
例如:@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檔案中的一些配置

struts
org.apache.struts2.dispatcher.FilterDispatcher
actionPackages com.struts2.action1,com.struts.action2-->

com.struts2.action

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.