File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Servlet Context and Servlet 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 Context and Servlet" Watch "Servlet Context and Servlet" New topic
Author

Servlet Context and Servlet

Sudhanshu Mishra
Ranch Hand

Joined: May 28, 2011
Posts: 207

Hi all,
I am a bit confused regarding who is created first ,a servlet ,or a servlet context?
According to my logic ,servlet context must be created first.
Please correct me if I am wrong.


Thanks and regards.
pravin venkat
Greenhorn

Joined: Mar 30, 2012
Posts: 20
servletContext(is required for) --> servletConfig(is required for) --> Servlet Initialization
Sudhanshu Mishra
Ranch Hand

Joined: May 28, 2011
Posts: 207

Thanks Pravin,
So may i conclue that the servlet is created after the servlet context has been created,and hence a listener class(ContextLoaderListener) will run before a servlet(DispatcherServlet)?

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

ContextLoaderListener is a Spring class and has nothing to do with Servlets when Spring isn't being used.

If you mean ServletContextListener, then yes, this listener's contextInitialized() method will fire before any servlets are loaded or requests are processed.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18125
    
    8

If you think of the servlet context as representing the whole web application, the answer becomes obvious, doesn't it?
pravin venkat
Greenhorn

Joined: Mar 30, 2012
Posts: 20
Sudhanshu Mishra wrote:Thanks Pravin,
So may i conclue that the servlet is created after the servlet context has been created,and hence a listener class(ContextLoaderListener) will run before a servlet(DispatcherServlet)?

Thanks.


Yes
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Context and Servlet
 
Similar Threads
Users in a server
Q6 from chap 5 of HSFJ
Servlet context and config
Servlet Context
Servlet Context parameters