Session variables with Ajax

S

soup_or_power

Hi All

I use Ajax to call a JSP page that is heavy duty. After the JSP gets
done it will set a session variable as session.setAttribute("flag",
"1"). I read the session from Java and process it as follows:
try {
for (;;) {
Map m=
FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
String flag=(String)m.get("pushsession1");
System.out.println("flag=" + flag);
if (flag == null || flag.trim().equals("")){
Thread.sleep(2000);
logger.debug("waiting for pushsession1");
System.out.println("waiting for pushsession1");
}
else {

m.put("pushsession1", "");
System.out.println("done pushsession1");
logger.debug("done pushsession1");
break;
}
}
} catch (Exception e) {};

I expect the java method to wait until the JSP gets done. What I am
seeing is the session in Java sometimes gets the correct value for
flag and some times gets null for the flag. Could someone please
clarify how to integrate JSP with Java using Ajax?

I tried using the volatile for flag as : volatile String flag=... and
got compiler error.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top