I have two servlets. 1 serves as a primary server for my applet clients and other serves as secondary.
I just want for my servlet2(secondary) to ask servlet1 about number of sessions it have, suppose servlet1 is storing that information in an int, then how can we access that int from servlet2. provided that both servlets are different web projects.
This is a bad design you are trying to implement. What you really need is an Application Scope Variable
Quoting from http://www.daniweb.com/web-development/jsp/threads/78622/difference-between-session-and-application-scope-at-jsp
‘Application scope is the broadest scope and should only be used when necessary. You can create objects bound at application level in JSPs that are not session-aware, so application scope is useful for storing information when using these types of JSPs. You can also use application-bound objects to share data among different sessions of the same application.’
Take a look at this example that makes use of a counter as Application Scope Variable http://java.sun.com/developer/onlineTraining/JSPIntro/exercises/Counter/index.html