Bookmark Topic Watch Topic
  • New Topic

when does a servlet clas get servletness ?

 
Rauhl Roy
Ranch Hand
Posts: 401
Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
Prem Kashyap
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Originally posted by Prem Kashyap:

Option 1 is correct.


How can any option be correct when "servletness" is not a real term?
 
Rauhl Roy
Ranch Hand
Posts: 401
Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
In that case, can you define 'servletness'?
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Report post to moderator
After the servlet object is created by invoking the default constructor and before the call to the init() method is made.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 401
Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 3830
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Yes.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 52
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
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 ]
 
    Bookmark Topic Watch Topic
  • New Topic