What's the best (most secure) way of implementing session handling in a web server? I'd like to add that, but don't know how to implement it really. Is cookies a "must" for session handling? (To be able to identify which session)
The session handling isn't really your concern. It is handled by the HttpSession
class (read the description in the javadoc!), which you can obtain by calling request.getSession()
.
It works in two ways (no need for you to do anything to support them):
- using a session cookie (if cookies are allowed)
- using url-rewriting - appending the session id (
JSESSIONID
) to the URL.
(Note: it is actually handled by the servlet container (Tomcat, jetty, etc) which provides an implementation of HttpSession
)
Assuming that you're talking about a servlet container, then session handling comes backed in. See the relevant part of if the JavaEE tutorial. It covers the session API, as well as how sessions are tracked (cookie or URL rewriting).
Session handling is handled by the web container. If you want safety from prying eyes, use https (enforced in web.xml).
What you might be interested in also, is how the user identifies himself to the web container. Several options exist, where the most secure is the client uses a web browser with a digital certificate. That is quite tedious, but very secure :)