隨筆 - 16, 文章 - 0, 評論 - 0, 引用 - 0
          數(shù)據(jù)加載中……

          Struts2 注解基礎(chǔ)

          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]

          先是報(bào)這個錯,因?yàn)閟truts2的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默認(rèn)result頁面存放在WEB-INF/content.(可以通過struts.convention.result.path屬性來設(shè)置)。

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

          2.convention plugin查找類的規(guī)則

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

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

          3.convention plugin類對應(yīng)URL規(guī)則

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

          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對應(yīng)頁面名稱

            頁面命名與類名規(guī)則相同,再加上“-”與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 閱讀(209) 評論(0)  編輯  收藏


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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 绥德县| 清原| 乌鲁木齐县| 曲水县| 东乡| 河间市| 瓦房店市| 汝南县| 石阡县| 弥渡县| 光山县| 石棉县| 连平县| 江安县| 黄石市| 镇康县| 新邵县| 洞头县| 芷江| 临湘市| 辽源市| 韩城市| 常德市| 赤峰市| 凯里市| 乾安县| 宁陕县| 扬中市| 崇州市| 磐石市| 江北区| 永济市| 高密市| 娄底市| 兴业县| 珠海市| 徐闻县| 扶绥县| 茶陵县| 凌云县| 烟台市|