0

While loading the view page I am setting a session variable as:

request.session.setAttribute("list",list);

after that onclick of a button I am using ajax call to refresh the list. in backend I am able to see the latest list contents. But in UI I am using :

List<String> cList = (List<String>)session.getAttribute("list");

but even after the list is changed I am not able see the latest list contents.Still the old list contents are displaying on the page. Need some suggestions on how to resolve this issue.

var refreshThisDiv= "refreshThisDiv";
            var goUrl= "unametest/getUserNamesList;
            var httpRequest=null;
            var refreshContent = "null";
            httpRequest = XMLHTTPObject();
            httpRequest.open("POST", goUrl, true);
            httpRequest.onreadystatechange = function () {ajaxFcuntion(refreshThisDiv,httpRequest); } ;
            httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            httpRequest.send(null);

//ajaxFcuntion
function ajaxFucntion(refreshThisDiv,httpRequest){

    if (httpRequest.readyState == 4)
    {
        if(httpRequest.status == 200)
        {
            results =  httpRequest.responseText; 
if(results!=null){

            <%

            List<String> list = (List<String>)request.getSession().getAttribute("list"); %>
//display data from list
}

}

user3213490
  • 157
  • 1
  • 9

1 Answers1

1

Actually as expected, you are mixing two different codes. You have to realize, where and when each code is executed - JSP on the server when the page is requested and rendered (i.e. before the response is send to the browser) and Javascript in the browser, after the browser receives the already generated response. For more details how to use AJAX, JSP and servlets together, read this question and answer carefuly.

Community
  • 1
  • 1
Jozef Chocholacek
  • 2,874
  • 2
  • 20
  • 25