我需要在加載JSP時調用一個動作。跟蹤訪問該頁面的用戶數量。如何從Ajax或JavaScript調用Struts1操作?
我有一個行動VisitorCounterAction
,它更新數據庫。 在加載JSP時,我打電話給ajax函數callCounter()
;
{
alert("callCounter");
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
// i need some correction here
xmlhttp.open("GET",VisitorCounterAction,false);
xmlhttp.send(null);
alert("callCounter returned from Action");
}
我得到一個異常:
/web/guest/content?p_p_id=31&p_p_lifecycle=0&p_p_state=pop_up&p_p_mode=view&_31_struts_action=%2Fimage_gallery%2Fview_slide_show&_31_folderId=10605 generates exception: null
請幫助我。或者任何其他方式來調用該行動。 我無法重新加載頁面,因爲它會再次調用onload函數。
感謝, 了Dj
爲什麼「p_p_state」的值是「pop_up」? – Shashi 2010-03-03 07:57:13
你是否已經通過你的動作類代碼進行了調試?你在哪裏得到空錯誤?我正在使用Struts 1.3進行一些AJAX調用,並且我沒有在我的操作類中做任何特殊的事情,所以我猜你的問題可能與你發送的參數有關。 – bittersweetryan 2011-09-06 01:22:49