This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Servlet init() and service() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet init() and service()" Watch "Servlet init() and service()" New topic
Author

Servlet init() and service()

S Majumder
Ranch Hand

Joined: Jun 03, 2009
Posts: 244
Hi every body, I have a query :

Can I call service() under the init() ?
Can I call init() under service() ?

regards,
S
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60048
    
  65

They're just methods, you can do anything you want. Whether it's completely silly or not (hint: yes) is another matter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
S Majumder
Ranch Hand

Joined: Jun 03, 2009
Posts: 244
Thanks Bear Bibeault ,
for your reply ,
so suppose I am calling service() under init() what will happen ?
suppose I am calling init() under service() what will happen ?

regards,
S
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60048
    
  65

It's just Java. Whatever code is in the methods will execute. It'd be a completely silly thing to do, but nothing prevents you from being silly.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39544
    
  27
In other words, nothing special will happen, in particular, the servlet will not be initialized (if that's what you expected to happen). Initialization doesn't happen because the init() method is called - the init() method is called because the servlet is initialized (which is something the servlet container does, not your servlet code).


Ping & DNS - updated with new look and Ping home screen widget
lianchi gao
Greenhorn

Joined: May 12, 2007
Posts: 7
Ulf Dittmer wrote:In other words, nothing special will happen, in particular, the servlet will not be initialized (if that's what you expected to happen). Initialization doesn't happen because the init() method is called - the init() method is called because the servlet is initialized (which is something the servlet container does, not your servlet code).


i think he is right, because you can't control the servlet container.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60048
    
  65

lianchi gao wrote:i think he is right

No thinking needed -- he's exactly right.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet init() and service()
 
Similar Threads
Calling init or destroy.
what happens if i call destroy() method in init() or service() method ?
init()
call detroy in init
init() method ........