隨筆 - 16, 文章 - 0, 評論 - 0, 引用 - 0
          數據加載中……

          Struts2 注解基礎

          The Struts dispatcher cannot be found.  This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]

          先是報這個錯,因為struts2的filter是*.action的原因。改為以下即可。

          <filter-mapping>
          <filter-name>struts2Filter</filter-name>
          <url-pattern>/*</url-pattern>
          <dispatcher>REQUEST</dispatcher>
          <dispatcher>FORWARD</dispatcher>
          </filter-mapping>

           

          1.convention plugin插件

          convention plugin默認result頁面存放在WEB-INF/content.(可以通過struts.convention.result.path屬性來設置)。

          如 http://localhost:8080/hello-world該url將訪問WEB-INF/content/hello-world.jsp。

          2.convention plugin查找類的規則

              convention plugin會查找struts、struts2、action、actions等包里的滿足以下條件的類(好像可以設置)

          • 實現或繼承com.opensymphony.xwork2.Action、ActionSupport的類。
          • 或者action結尾的類名
            修改包查找規則修改下面兩個屬性
          <constant name="struts.convention.package.locators" value="test" />
          <constant name="struts.convention.package.locators.basePackage" value="com.test" />

          3.convention plugin類對應URL規則

            在struts、struts2、action、actions等包下生成“/”,更深層次則繼續以“包名/”,類名子目全小寫,按駝峰法分隔單詞添加“-”。舉例如下:

          com.example.actions.MainAction -> /main
          com.example.actions.products.Display -> /products/display
          com.example.struts.company.details.ShowCompanyDetailsAction -> /company/details/show-company-details

          4.result對應頁面名稱

            頁面命名與類名規則相同,再加上“-”與result值即可,如果找不到result的頁面,似乎會返回到省略result名稱的頁面,還有success可省略,如下:

          URLResultFile that could matchResult Type
          /hello success /WEB-INF/content/hello.jsp Dispatcher
          /hello success /WEB-INF/content/hello-success.htm Dispatcher
          /hello success /WEB-INF/content/hello.ftl FreeMarker
          /hello-world input /WEB-INF/content/hello-world-input.vm Velocity
          /test1/test2/hello error /WEB-INF/content/test/test2/hello-error.html Dispatcher


          5.chaining

            例子:foo action找不到result頁面,會自動查找foo-bar action

          package com.example.actions;

          import com.opensymphony.xwork2.Action;
          import com.opensymphony.xwork2.ActionSupport;

          public class HelloAction extends ActionSupport {
          @Action("foo")
          public String foo() {
          return "bar";
          }

          @Action("foo-bar")
          public String bar() {
          return SUCCESS;
          }
          }

           

           

            

            

           

           

           

           

          參考:

          struts2 convention-plugin文檔

          http://www.vaannila.com/struts-2/struts-2-example/struts-2-annotation-example-1.html

          http://apps.hi.baidu.com/share/detail/48320875

          posted on 2011-12-30 20:14 yita 閱讀(208) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 雷山县| 厦门市| 凤城市| 锦屏县| 安康市| 孝昌县| 廊坊市| 信宜市| 塔河县| 京山县| 枝江市| 甘洛县| 红河县| 普洱| 辽阳县| 怀集县| 于都县| 鄄城县| 岑巩县| 克东县| 新建县| 鄂托克前旗| 安陆市| 富锦市| 海兴县| 呈贡县| 鄄城县| 奈曼旗| 石泉县| 讷河市| 宜良县| 阿荣旗| 自治县| 鄂托克前旗| 合肥市| 濮阳市| 镇远县| 鹿泉市| 二连浩特市| 泽普县| 治多县|