Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Explicitly instance of Servlet

 
Rahul Juneja
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody tell me whether we can Explicitly create the instance of a Servlet.I mean
1)'Not by Calling Servlet first time or
2) Load on Startup'.

Does anybody know can we create an instance of Servlet without these options.

This question was asked to me in an interview.

Thanks,
Rahul
[ June 11, 2004: Message edited by: Rahul Juneja ]
 
Ivor Lithan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not quite sure what you mean, but if you mean what I think you do, you could do :



or am I missing what you are asking?
 
Rahul Juneja
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dear,

I was asking the same but one more Question which comes in my mind is that what is the practical implementation of this.

Can you please give me some idea about that.

thanks,
Rahul Juneja
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, a servlet is just a Java class that happens to implement a particular interface. There's nothing to stop you (other than the potential for confusing a reader, and other issues of general good design) from giving it a "main" method, and/or a constructor, and creating an instance of it in the way you would any other Java object.

Of course, if you create an instance of a servlet class yourself, there will be no container that knows about it, so it will never receive HTTP requests, but I gues that's not what you want, is it?
 
Ivor Lithan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear???

Well, the one time I used that was when I had a servlet that implemented runnable, with the idea being I could have a thread running and then query it through the web front end - and this servlet was kicked off by a scheduler that I had written - and so it used that bit of code to start it all off - other than that I've never used it for anything
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic