when does a servlet class get servletness ? 1.when init() method is invoked by the container. 2.when service() method is invoked by the container. 3. when the container loads the servlet class. 4.when the continer reads/sees load-on-startup tag. 5. when the container recives the first request. [ November 08, 2006: Message edited by: Rauhl Roy ]
Originally posted by Rauhl Roy: when does a servlet class get servletness ? 1.when init() method is invoked by the container. 2.when service() method is invoked by the container. 3. when the container loads the servlet class. 4.when the continer reads/sees load-on-startup tag. 5. when the container recives the first request.
[ November 08, 2006: Message edited by: Rauhl Roy ]
I would say that a Servlet gets it Servletness when it is parameterized by the web.xml file. Without being defined in the web.xml file, the Serlvet does not have a potential ServletConfig, and on modern web servers, is not ivocable or loadable by a web container.
Originally posted by Rahul Bhattacharjee: After the servlet object is created by invoking the default constructor and before the call to the init() method is made.
Nope. After init().
Javaranch Servlet FAQs says: "You can't make use of the constructor because the container calls it and therefore you can't pass any parameters to the constructor. Also at the point the constructor is called the class is not really a Servlet because it doesn't have a reference to the ServletConfig, which provides all the initialisation parameters etc."
Joined: Nov 29, 2005
Originally posted by Adeel Ansari:
Nope. After init().
By servletness I mean , when a user code has access to servlet config and servlet context.You are right in your own way. ;-)
IMO, the important thing about a servlet is being able to handle requests via its service, doGet, doPost etc. methods. Since those won't be called until after init has run, everything before that is kind of irrelevant.
But if a Servlet isn't even configured in the web.xml file, it doesn't even exist.
The web.xml file and the Java code that extends the HttpServlet class is like the sperm and the egg. When they come together, we have conception. Everything after that point is just details. That's when SERVLETNESS happens.
and if you notice that before calling init() [this is what be are suppose to override]the config is set in a class level variable for further use.
Does this justify my answer. sorry if I have created some issue regarding this due to my language.
Joined: Oct 10, 2006
I think we are unnecessarily extending this topic. In simple words: Servlet is nothing but a java class when it constructor runs. Only when the init method runs, it becomes a real sevlet. Some may argue it gains it servletness inside the init method or after init method completes. Some may also feel the term servletness is not a real term. But the point is that most of the person arguing are smart enough to know what is a Servlet and what are its basic functionality. So lets put a stop to it here. I hope all agree.
Next Question: HttpSession Attributes are Thread-Safe or not?
The longer this thread continues, the more convinced I am that, introducing the term "servletness", not only isn't useful but is confusing and misleading. You will not find the term "servletness" anywhere in the servlet spec and people who come here to learn about servlets should not have to wade through terminology that was made up here.
I'm closing this thread. If anyone wants to add to, question, or argue with this definition of servlet, please start a new thread on the "Definition of a Servlet". [ November 10, 2006: Message edited by: Ben Souther ]