警告:?No?configuration?found?for?the?specified?...
今天首次使用Struts2,配置一切正常,使用常用tag也正常,但是在使用<s:form>標(biāo)記時(shí),發(fā)現(xiàn)控制臺(tái)總是輸出警告信息,
警告信息內(nèi)容如下:
警告: No configuration found for the specified action: 'ShowMessage'in namespace: ''. Form action defaulting to 'action' attribute'sliteral value.
2008-9-6 11:35:47 org.apache.struts2.components.FormevaluateExtraParamsServletRequest
警告: No configuration found for the specified action: 'ShowMessage'in namespace: ''. Form action defaulting to 'action' attribute'sliteral 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>
打開(kāi)showmsg.jsp頁(yè)面時(shí),就出現(xiàn)上述異常。嘗試了各種配置和訪問(wèn)方法,均出現(xiàn)警告。搜索網(wǎng)絡(luò)給出的答案幾乎都說(shuō)把<s:formname="ShowMessage" method="post" action="/hello/ShowMessage.action">中的.action去掉就可以解決了,做了測(cè)試,問(wèn)題仍然沒(méi)有解決。更有人讓把<s:去掉,不用tag,直接寫(xiě)<form>這個(gè)當(dāng)然不會(huì)有問(wèn)題,但是一會(huì)用標(biāo)記,一會(huì)不用,很雜亂,并且不是解決問(wèn)題的根本之道。
解決方法:
經(jīng)過(guò)測(cè)試發(fā)現(xiàn),是沒(méi)有正確使用tag的原因,這種情況下,正確的寫(xiě)法應(yīng)該是,<s:formname="ShowMessage" method="post" action="ShowMessage"namespace="/hello" >
原因分析:
因?yàn)殚_(kāi)始使用的struts2標(biāo)簽(form)并未指定namespace屬性。所以struts2會(huì)默認(rèn)從根命名空間"/"搜索action'/hello/ShowMessage.action',如搜索不到則進(jìn)入默認(rèn)命名空間''搜索action串,在默認(rèn)命名空間中是肯定找不到自己定義的action的,所以,struts2拋出一個(gè)警告信息。
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶(hù)發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)
點(diǎn)擊舉報(bào)。