?
http://blog.csdn.net/carefree31441/article/details/4857546
?
使用 Struts2,配置一切正常,使用常用tag也正常,但是在使用<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。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
