-1

I just wonder why does only one copy of a servlet get created. And if a brower requests a servlet for the first time. How does servlet deal with that. I know java will compile code before running it. How about servlet? Last, How is information stored in a session object? I am new to java servlet, please help me. Thanks!

SPG
  • 6,109
  • 14
  • 48
  • 79
  • Where does it say that only one copy gets created? And what does your second sentence mean? Question(s) cannot be answered in its/their current form. – user207421 Jul 20 '11 at 10:41
  • 1. by spec only one instance is created. 2. they can ;) – Bozho Jul 20 '11 at 10:43

2 Answers2

3
  • one servlet instance is created, because no more are needed. Each request is passed through the service(..) method in a separate thread
  • servlets are already compiled when starting the server - they are .class files
  • there is a <load-on-startup> configuration that lets you specify when should the container instantiate the servlet
  • session is identified by a session cookie, which is sent with each request. When a client sends the session id, it is looked up in a table and the appropriate Session object is returned.
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
1

Yes only one instance of servlet created for the first time when user hit URL that is mapped to it. and stays into the memory until its unloaded by classloader.

each request served in separate thread .

Session is a scope , each user has associated session id , generally it is mapped from the cookie from the request header and server identifies that this user is coming from this session


See Also

Community
  • 1
  • 1
jmj
  • 237,923
  • 42
  • 401
  • 438