Frage

I have a webpage that contains a header and a main section. Both the header and the main section make the same call to one particular Java API running on my server. The first call should establish a session and set a flag in the session which prevents the second call from proceeding until the first call completes (e.g. its blocking).

What currently happens is the header usually makes the call first, establishes a session and sets the flag. Then, the main section makes the call; however, for some reason, it is establishing an entirely new session so it never sees the flag and both calls run consecutively. This consecutively running process causes a problem with the underlying database which is a separate issue.

So my question is, why are two separate sessions being established? Why isn't the second call recognizing the first session and using it?

War es hilfreich?

Lösung

Sessions are usually established by cookies which are sent using HTTP headers. A web browser that is asked by server to save a session cookie typically uses that for any subsequent requests: however, for any request that has happened in between, session information will not be present. Thus new sessions can be created in between.

Also, if a browser chooses to reject session cookies, you would get a new session created for every request. That's something that's beyond your control.

This behaviour is general to HTTP traffic/web browsing and not related to any specific product (e.g. Tomcat).

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top