How to call Struts1 Action from Ajax or JavaScript?

I need to trigger an action when loading a JSP. To track the number of users who visited this page.

I have an action VisitorCounterActionwhere it updates the database. When loading the JSP, I call the ajax function 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");
        }

I get an exception like:

/ 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

Please help me with this. Or any other way to trigger an action. I cannot reload the page since it will call the load function again.

Thanks Dj

+3
source share
3

URL-. struts.xml . , VisitorCounterAction. , Action, , struts.xml.

struts . .do.

, : VisitorCounterAction.do.

, :

  xmlhttp.open("GET","VisitorCounterAction.do",false);

URL-, open() xmlHttp.

0

XMLHttpRequest object open , URL- . Struts, VisitorCounterAction. - :

xmlhttp.open("GET", "/viewCounterAction.do", false); 
0

If you are using Liferay 4.2, this link may help you ( http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Ajax+Toolkit ). Liferay 4.2 has its own javascript API suite for executing AJAX functionality (implemented in jquery).

0
source

Source: https://habr.com/ru/post/1733358/


All Articles