Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class HttpSession
- Object
- HttpSession
State kept for one client across requests, found again through a cookie.
@PostMapping("/login")
public void login(HttpServer.Request request, @RequestBody Map body) {
...
HttpSession session = request.getSession(true);
session.changeSessionId(); // never keep a pre-login id
session.setAttribute("user", userId);
}
A session is created only when something asks for one with
getSession(true), so a server that never does sets no cookie and keeps
nothing. The cookie is HttpOnly, SameSite=Lax and, on a TLS
server, Secure; its name, lifetime and store are configured under
cn1.session.*.
Attributes live in the SessionStore. The in-memory store keeps any
object; the database store keeps what Json can write – strings,
numbers, booleans, and maps and lists of those – because it has to read them
back in another process.
A session-scoped bean is never written to a store: the server that built it keeps it in memory for as long as the session lives, and runs its destroy methods when the session is invalidated, expires or the server stops. Another instance behind a load balancer builds its own.
Methods
Inherited methods
Method details
getId
public synchronized String getId()isNew
public synchronized boolean isNew()getCreationTime
public long getCreationTime()getLastAccessedTime
public synchronized long getLastAccessedTime()getMaxInactiveInterval
public synchronized int getMaxInactiveInterval()setMaxInactiveInterval
public synchronized void setMaxInactiveInterval(int seconds)getAttribute
public synchronized Object getAttribute(String name)setAttribute
public synchronized void setAttribute(String name, Object value)removeAttribute
public synchronized void removeAttribute(String name)consumeAttribute
public Object consumeAttribute(String name)
throws IOExceptionThrows
java.io.IOException- if the store cannot perform the atomic operation
getAttributeNames
public synchronized List getAttributeNames()invalidate
public synchronized void invalidate()isValid
public synchronized boolean isValid()changeSessionId
public String changeSessionId()