tags:

views:

28

answers:

1

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?

+1  A: 

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.

BalusC
Thank you for the useful information.
Lalchand
You're welcome. I see that you're pretty new here and that you never voted or accepted an answer before. I suggest to read the http://stackoverflow.com/faq to learn how to get the most of Stackoverflow and keep its spirit :)
BalusC
yeah done cheers ,thanks for remanding me
Lalchand