乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      There is no Action mapped for namespace / and action name

       螞蟻搬家 2009-12-04
      struts2的異常There is no Action mapped for namespace / and action name --轉(zhuǎn)
      2009-01-19 00:28
      把 package 元素里的 namespace 去掉.


      調(diào)用 action 名稱的頁面應(yīng)該放在 namespace 的名稱里面(文件夾,路徑)

           <package name="example" namespace="/example" extends="struts-default">
               <action name="HelloWorld" class="example.HelloWorld">
                   <result>/example/HelloWorld.jsp</result>
               </action>
      HelloWorld.jsp 文件應(yīng)該放在 namespace="/example"   example 文件夾里面. 否則調(diào)用 action 會(huì)出錯(cuò).

      關(guān)于 namespace :

      struts.xml 文件中 package 元素下 namespace 屬性的作用
                
      說在前面的話:
      namespace的作用是控制相應(yīng)package下的action的url地址,url地址在web編程中是基礎(chǔ)中的基礎(chǔ). 我們的程序不同的功能實(shí)際上就是對(duì)相應(yīng)url地址的訪問來觸發(fā)的,這個(gè)要牢牢掌握,有點(diǎn)象java的classpath


      原文: http://www./Unmi/archive/2008/05/26/203014.html
      Struts2 的 struts.xml 中是分 package 配置的,可以為 package 設(shè)置 namespace 屬性,如

      <package namespace="/secure"   ....>
           ......
      </package>

      如果沒有指定 namespace 屬性,默認(rèn) namespace 是 ""。使用 namespace 可以方便于按不同目的規(guī)劃對(duì)應(yīng)用的訪問規(guī)則。比如不同 namespace 下配置了不同的攔截器就可以實(shí)現(xiàn)權(quán)限的控制,如 "/secure" 下已登陸用戶才能訪問,"/public" 下可公開訪問的。

      配置了 namespace 直接就是反應(yīng)在訪問 URL 上,例如 namespace="/secure"   name="test" 的 action

      <package namespace="/secure"   ....>
             <action name="test"   ....
      </package>

      訪問它的 URL 就是 http://ip:port/context/secure/test.action,那如果在 namespace "/secure" 下沒有 test action 會(huì)出現(xiàn)什么情況呢?Struts 還會(huì)嘗試在默認(rèn) namespace,即 "" 下找 test。

      再舉個(gè)例子,URL 是 http://ip:port/context/some/path/test.action 時(shí),如果在 "/some/path" namespace 下找不到 test action,也是到 "" (default namespace) 下找 test action,但不會(huì)去 "/some" 下找的。

      用標(biāo)簽 <s:url value="/secure/test.action"/>   對(duì)應(yīng)頁面源文件是 /context/secure/test.action

      稍有麻的就是 <s:form action="/secure/test.action" .... 對(duì)應(yīng)的源文件是 <form action="/context/secure/test.action" ...

      但是后臺(tái)會(huì)有警告:

      警告: No configuration found for the specified action: '/secure/test.action' in namespace: ''. Form action defaulting to 'action' attribute's literal value.

      Struts2 把 action 屬性值當(dāng)整一個(gè) Action Name 了,但這也不影響使用,這個(gè) URL 正好能與 (package namespace) + (action name) 合上拍。

      但是對(duì)于使用了動(dòng)態(tài)方法調(diào)用(struts.enable.DynamicMethodInvocation = true)就沒這么幸運(yùn)了。很容易想當(dāng)然的

      <s:form action="/secure/test!update.action" ....   生成的 HTML 源文件卻是 action="/TestStruts2/om/test"

      同時(shí)后臺(tái)的警告信息是:

      警告: No configuration found for the specified action: '/secure/test' in namespace: ''. Form action defaulting to 'action' attribute's literal value.

      很顯然對(duì)于這個(gè) action="/TestStruts2/om/test",提交時(shí)是會(huì)得到 HTTP Status 404 - /context/secure/test   錯(cuò)誤。

      正確的用法是 <s:action...> 也有一個(gè) namespace 屬性,對(duì)了,就是

      <s:form namespace="/secure" action="test!login">   生成的 HTML 源文件是:<form action="/TestStruts2/om/test!login.action" ....>

      我們要的就是這個(gè)。

      如果不配置 namespace 屬性,我們能不能在訪問 action 時(shí)也用上目錄層次呢?可以,那是在 struts1 習(xí)慣的做法,配置 <action name="secure/test" ....> name 中使用斜杠,但在 Struts2 中 Action Name 中使用斜杠需要設(shè)置

      struts.enable.SlashesInActionNames=true                       默認(rèn)為 false

      可是 Struts2 大概不贊同這種做法,力挺 namespace 的作用。

      對(duì)于上面使用了斜框的 Action Name,<s:form 中的寫法要用

      <s:form action="secure/test">                  生成 HTML 源文件:<form action="/context/secure/test.action" .....

      <s:form action="secure/test!update">             生成 HTML 源文件:<form action="/context/secure/test!login.action" .....


      上面的 action 后加不加 .action 無所謂,只是要保證 <s:form>   的 action 屬性一定要與 struts.xml 中的 <action> 的 name 匹配上,如果你自作多情的在前面加個(gè)斜杠,如寫成了

      <s:form action="/secure/test!update"> 、 <s:form action="/secure/test">   或者 <s:form action="/secure/test!update.action">   生成的 HTML 源文件就都成了:<form action="/context/secure/test" .....

      這也是從 Struts1 帶來的弊病,因?yàn)?Struts1 中 <html:form> action 屬性對(duì)應(yīng)的是 <action> 的 path,而 Struts2 中 <s:form> 的 action 屬性對(duì)應(yīng)的是 <action> 的 name;name 要完全匹配,path 可以加些層次。

      我為何以費(fèi)這么些功夫來搞清楚這個(gè)呢,也就是因?yàn)槭褂?<s:form action=""> 是時(shí)而行,時(shí)而不行,很似迷惑,一度懷疑是應(yīng)用服務(wù)器在從中作梗。坦白的說,就是寫本篇日志完成紅線以上的內(nèi)容時(shí)仍未能知曉就理,這也正好映證了寫下來的意義。因?yàn)樵谶@過程中你在試圖讓別人更好的理解,倘若自己都說不清,他人只能是云里霧里了

       

      最近一段時(shí)在學(xué)習(xí)著使用Struts2的框架,自己寫了一個(gè)例子,可是剛上來就遇到了一個(gè)讓我頭痛的問題。

      There is no Action mapped for namespace / and action name UserAction

      在網(wǎng)上找了好久才找解到的方法,其實(shí)是因?yàn)槲业膕truts.xml文件放錯(cuò)了位置,服務(wù)器沒有加載上導(dǎo)制。

      之后將struts.xml文件移到src目錄下就可以了。

      將自己在網(wǎng)上的搜到的解決方案貼在這里供網(wǎng)友們以后解決問題的時(shí)候參考。

      可能的原因:
      1.-----首先查看你的struts.xml 文件是否在src目錄下;
      2.-----檢查struts.xml文件的語法是否正確:                如果1正確的話那就一定是struts.xml文件的問題:           <?xml version="1.0" encoding="UTF-8" ?>
      <!DOCTYPE struts PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
          "http://struts./dtds/struts-2.0.dtd">

      <struts>
      <package name="struts2" extends="struts-default">

        <action name="login" class="com.test.action.LoginAction">
        <result name="success">/result.jsp</result>
        </action>
      </package>
      </struts>  
                那么就只有是紅字的部分寫錯(cuò)了 查看你的是否吧struts-default中間的“-”錯(cuò)寫成了struts=default;

      二.確定名稱是 struts.xml
      三.粗心,仔細(xì)檢查配置文件,和excute方法的代碼

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多