Trouble With retrieving Session Attributes after Ajax call

228 views Asked by At

I am trying to set some variables in session through an ajax call in my jsp and I am trying to retrieve these values in the same jsp page.

Problem is that I am not getting these values once the JSP page is rendered,but once I refresh the page these values are accessible.How it is happening?

P.S- I cannot put a reload method as it changes my other variables state.

Here is my JSP page

function call() {

//LocalStorage = new LocalStorage();
var Request_id= <%=session.getAttribute("Request_id")%>;

var tabIndex=0;
var source=1;
var action = "queryinterfaceresults_getStatus.action";
var serializedForm ="&Request_id="+Request_id;
alert(Request_id+":::Request_id");
$.ajax({
      url: action,
      type:"POST",
      data:serializedForm,
      success: function(data){
          alert(data)
        var matchcount  = <%=session.getAttribute("matchcount")%>;
        var postedcount = <%=session.getAttribute("postedcount")%>;
        var completedcount = <%=session.getAttribute("completedcount")%>;

        if(postedcount!=null && completedcount!=null && postedcount == completedcount  )
        {
            alert("PostedCount::: "+postedcount)
            alert("Completedcount::: "+completedcount)
            getRequestHistoryDetails(matchcount,postedcount,completedcount,source,Request_id);
        }  
        else if(postedcount!=completedcount  )
        {

            alert("ElsePostedCount::::"+postedcount)
            alert("ElsecompletedCount::::"+completedcount)
             //alert("p");
               //d1 = new Date();  
                /* var difference = d1.getTime() - d.getTime();
               var minutesDifference = Math.floor(((difference/1000)/60));
                       difference -= minutesDifference*1000*60; 
               alert("min.00000000000000000diff::::"+minutesDifference );
                        var secondsDifference = Math.floor(difference/1000);
                     //  difference -= secondsDifference*1000 */
              // alert("secondsDifference::::"+secondsDifference ); 
            /*  if(secondsDifference>60)
                {
                    $('#loadingImage').hide();
                    alert("More Parameters are required or a tighter profile needs to be used.");
                }*/


                /* {
                    call() ;        
                }   */

        }
        /*  else if($('#status').val()!=null && $('#status').val()=='e' )
        {
                    //alert("Error in primematch!!!!"); 
                    $("#message").hide();
                    $("#error").html("<font color='red'; fontsize='10px';>Error in Service, Please repost!!!</font>");
                    $("#QueryInterfaceResults").hide();

        } */


        },
        error: function(e,request){
            console.log("error",$('#status').val())
            <%--  alert("Problem in citizen matches");
           window.location.href = "<%=request.getContextPath()%>/index.jsp"; --%>
}
});

}

and the action class method

public String getStatus() {



        logger.info("In getStatus():::::::::::::::" + getRequest_id());
        QueryInterfaceResultsManager manager = QueryInterfaceResultsManager.getInstance();
        try {
            RequestStatus requestStatus = manager.getStatus(getRequest_id().toString().trim());
            logger.info("requeststatus :: "+requestStatus);
            logger.info("requestStatus.getPostedCount() :: "+requestStatus.getPostedCount());

            if (requestStatus != null) {
                logger.info("requestStatus in if "+requestStatus);



                session.put("postedcount", "1");//requestStatus.getPostedCount());
                session.put("completedcount", "1");//requestStatus.getCompletedCount());
                session.put("matchcount", "1");//requestStatus.getMatchCount());

            }
        } catch (Exception e) {
            logger.error("Error while getting ststus::" + e.getMessage());
        }
        return "statuspage";

    }
0

There are 0 answers