I want to know whether one session is been created开发者_开发知识库 for each IP address or for each browser instance?
I opened my JSP application in three browser windows. It creates three different sessions? Suppose I want to use a single session for multiple instance of browser, is it possible or not?
No, that's not possible (actually, that depends a bit on how you define "browser instance"). The session is under the hoods backed by a HTTP cookie. Such a cookie is browser-instance-specific. Each browser instance has its own set of cookies, saved separately in disk file system. It cannot be shared among different browser makes (IE, FF, Chrome, etc). It's however shared among different tabs/windows of the same browser instance.
You can however obtain the IP address using HttpServletRequest#getRemoteAddr()
and save the information in a broader scope along the IP address as key, in for example the application scope or a database. This has however some problems: this won't distinguish multiple users behind the same IP address, such as a big company network behind a proxy. This also won't work for people with a dynamic instead of static IP addresses.
The cookie or an user authentication mechanism (register, login, etc) is the most reliable way to track an unique and individual user among different HTTP requests.
精彩评论