File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Difference between container and servlet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Difference between container and servlet?" Watch "Difference between container and servlet?" New topic

Difference between container and servlet?

Sriram Sharma
Ranch Hand

Joined: Apr 12, 2006
Posts: 130
Hi All,

Can somebody give me explicit difference between a container and a servlet?
I can uinderstand that container contains the servlet and that container gives static objects like html, jpeg/gifs etc.
But what is the reason that we have container and for what reason we have servlets?
What is it that I can do with servlets as standalone?

Himanshu Kansal
Ranch Hand

Joined: Jul 05, 2009
Posts: 257

It's good that you understand that the container contains the servlet, but another important job the container does is to parse and serve the servlet's response to the request. Apart from this other important tasks of resource management for the servlet are done by the container. A servlet works in the limits of the container, is operational because of the container and can be accessed because of that. Security implementation might be another task to mention.

A servlet is only the operation that takes place when a particular request is made. This operation performed by the servlet is limited to the request only and relates to nothing external. Whereas there are processes a container has to perform when a request is made, but they may be independent of the request, like mundane.

An analogy could be the container as the OS and the servlet as the application s/w.

Sriram Sharma wrote: What is it that I can do with servlets as standalone?

standalone servlet? I am unaware of this part.


Experience and talent are independent of age
Sriram Sharma
Ranch Hand

Joined: Apr 12, 2006
Posts: 130
Thanks for that info Himanshu...
Anybody with anymore/more elaborate info on this would be great :-)

And yeah... Sorry for my last question in this post.
What I meant was...

"What can we do with a servlet container as a standalone?"
I agree. Here's the link:
subject: Difference between container and servlet?
It's not a secret anymore!