nich nich - 1 year ago 101
Java Question

java servlet problems

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.

Answer Source
  • 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.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download