Posted on 2008-08-27 15:42
Qzi 閱讀(4078)
評論(1) 編輯 收藏 所屬分類:
javascript
javascript是經典的敏感性語言,小小問題都會導致整體功能出錯。
自己調用document.form[0].submit()的時候,會出現submit is not a function錯誤(使用firefox的firebug調試,非常好用),原因是頁面的form中出現具有name=submit的元素,這樣會影響到javascript調用submit()函數,改掉那個name=submit的元素即可。
另外submit提交struts1.2的action時候,如果后面跟有?method=***等的參數,那么注意,這個函數里面不要出現有method等關鍵字。
例如函數:
function changeAction(methodArg, wayArg){
with (document.forms[0]) {
action="<html:rewrite page='/BgdInfoReportAction.do'/>?method="+ methodArg + "&way=" + wayArg;
submit();
}
}
使用?method=***是在使用dispatchAction時候的做法原來我的參數名稱是method和way,
結果報錯:Action[/BgdInfoReportAction] does not contain method named post
原因是?后的method變得沒有效,那么這個submit提交使用默認的post方法提交(servlet默認分為post和get方法嘛),
后來我將method改成methodArg和way改成wayArg,這個action就能夠正確執行。
我重復測試改與不改的效果,仍然與上面一樣。總結原因可能是是javascript的一些關鍵字沖突,所以盡量使用特殊一點的字符串作為變量名。