aspose file tools*
The moose likes Servlets and the fly likes when does a servlet clas get servletness ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic
Author

when does a servlet clas get servletness ?

Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

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 ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

What are your answers?

Long enumerated lists of questions tend to look like homework assignments. Javaranch is not an answer mill for homework or test questions.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Prem Kashyap
Ranch Hand

Joined: Oct 10, 2006
Posts: 52
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 ]

Option 1 is correct.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61628
    
  67

Originally posted by Prem Kashyap:

Option 1 is correct.


How can any option be correct when "servletness" is not a real term?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

Dear Mr Ben,

I am very sorry for asking the question like this.
in fact, this is my own creation. and got this doubt after reading HF book only.

And, when dicussed in the HF book it is clearly not written when does a servlet get servletsness exactly. SO there was no option but to put this question on the site.

And servletness may not be in the specifications but HF community, i think, has the right to use this word.

regards,
rahul
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

In that case, can you define 'servletness'?
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

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.

Just a thought.

-Cameron McKenzie
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
After the servlet object is created by invoking the default constructor and before the call to the init() method is made.


Rahul Bhattacharjee
LinkedIn - Blog
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
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."
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
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. ;-)
Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

Hello Mr Ben,

I did mean, Servletness is when a class file changed to a servlet by the container to process the request and response.

regards,
rahul
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by Rahul Bhattacharjee:


By servletness I mean , when a user code has access to servlet config and servlet context.You are right in your own way. ;-)


But before init(), how can a user use config and context???

But I do understand that container creates these objects and then call init() method. So if context and config is created before init(), that means we have got the servlet before init()... right?

Thanks.
[ November 09, 2006: Message edited by: rathi ji ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42602
    
  65
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.


Ping & DNS - my free Android networking tools app
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

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.



Has this thread gone on too long, yet?

-Cameron McKenzie
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61628
    
  67

Yes.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42602
    
  65
Originally posted by Cameron W. McKenzie:
But if a Servlet isn't even configured in the web.xml file, it doesn't even exist.


There is of course the evil InvokerServlet, which allows you to have servlets without a declaration in web.xml. In your analogy, does this qualify as (semi-)immaculate conception?
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Rahul Bhattacharjee:
By servletness I mean , when a user code has access to servlet config and servlet context.You are right in your own way. ;-)


Hence it means "after init()".
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
I think wheneven the servlet config and context are created , then it can be said that the servletness has been granted.

Below is the code from GenericServlet.java

public void init(ServletConfig config)
throws ServletException
{
this.config = config;
init();
}


The container calls the below version of init method.

public void init(ServletConfig config)

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.
Prem Kashyap
Ranch Hand

Joined: Oct 10, 2006
Posts: 52
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?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.

A Java class is a servlet if it implements javax.servlet.Servlet.
The easiest and most common way to do this is to extend an existing implementation, such as GenericServlet or HttpServlet.

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 ]
 
 
subject: when does a servlet clas get servletness ?