隨筆-200  評論-148  文章-15  trackbacks-0
          在使用<s:form>標記時,發現控制臺總是輸出警告信息,

          警告信息內容如下:

          警告: No configuration found for the specified action: 'ShowMessage' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
          2008-9-6 11:35:47 org.apache.struts2.components.Form evaluateExtraParamsServletRequest
          警告: No configuration found for the specified action: 'ShowMessage' in namespace: ''. Form action defaulting to 'action' attribute's literal value.

          showmsg.jsp代碼如下

          <%@ taglib prefix="s" uri="/struts-tags" %>
          ......
          <div>
          hello world
          <s:form name="ShowMessage" method="post" action="/hello/ShowMessage.action" >
          <s:textfield label="user name" name="username"></s:textfield>
          <s:submit></s:submit>
          </s:form>
          </div>
          ......

          struts.xml配置如下:
          ......
          <struts>
           <package name="hello" extends="struts-default" namespace="/hello">
           <action name="ShowMessage" class="com.historycreator.strutstest.ShowMessage">
           <result>/digg/showmsg.jsp</result>
           </action>
           </package>
          </struts>

          打開showmsg.jsp頁面時,就出現上述異常。嘗試了各種配置和訪問方法,均出現警告。搜索網絡給出的答案幾乎都說把<s:form name="ShowMessage" method="post" action="/hello/ShowMessage.action" >中的.action去掉就可以解決了,做了測試,問題仍然沒有解決。更有人讓把<s:去掉,不用tag,直接寫<form>這個當然不會有問題,但是一會用標記,一會不用,很雜亂,并且不是解決問題的根本之道。

          解決方法:
          經過測試發現,是沒有正確使用tag的原因,這種情況下,正確的寫法應該是,<s:form name="ShowMessage" method="post" action="ShowMessage" namespace="/hello" >

          原因分析:

          因為開始使用的struts2標簽(form)并未指定namespace屬性。所以struts2會默認從根命名空間"/" 搜索action '/hello/ShowMessage.action',如搜索不到則進入默認命名空間''搜索action串,在默認命名空間中是肯定找不到自己定義的action的,所以,struts2拋出一個警告信息。

          現在我們指定了namespace為/hello,則struts2會直接在/hello命名空間尋找。可以想象,如果在這么命名空間里找不到請求的action,也會拋出一條類似的信息。

          注意,<s:form name="ShowMessage" method="post" action="ShowMessage" namespace="/hello" >
          不能寫成<s:form name="ShowMessage" method="post" action="ShowMessage.action" namespace="/hello" >

          這樣仍然有對應的警告信息,并且提交后出現無法訪問的結果。因為沒有ShowMessage.action這樣一個action,這個.action不能由我們手工添加,Struts2會自動為你完成這個工作,并且手工添加是不行的,就不必多此一舉了。但是在其他的場合,比如使用超級鏈結,則可以加上這個.action。

          轉載請注明 historycreator.com

          posted on 2010-10-28 15:50 無聲 閱讀(10238) 評論(0)  編輯  收藏 所屬分類: 職場生活
          主站蜘蛛池模板: 南江县| 措美县| 水城县| 勃利县| 德惠市| 贵定县| 辽阳县| 永胜县| 镶黄旗| 安阳县| 巴青县| 石阡县| 格尔木市| 环江| 恭城| 雅安市| 两当县| 景谷| 吐鲁番市| 延安市| 洪雅县| 睢宁县| 奈曼旗| 革吉县| 四平市| 梁平县| 西青区| 武冈市| 化隆| 忻城县| 宜兰市| 永康市| 屯昌县| 新营市| 安国市| 平湖市| 夏津县| 隆安县| 宁南县| 沐川县| 伽师县|