Meaningless Drivel is fun!
The moose likes Servlets and the fly likes Can servlet be executed differently Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Can servlet be executed differently" Watch "Can servlet be executed differently" New topic

Can servlet be executed differently

Chandra Bairi
Ranch Hand

Joined: Sep 12, 2003
Posts: 152
hello friends,
I have written a servlet class which i will execute by putting the class file in WEB-INF/classes/com.(here com is the package where the servlet exists). Then I mention the proper descriptor in the deployment descriptor.
After that I execute the servlet from the web browser. This is the normal way of executing the servlet.
But is there any other way of executing the servlet.
Thanks in advance.

Frank Carver

Joined: Jan 07, 1999
Posts: 6920
Well, you can execute a servlet in any compatible servlet container. For testing purposes some people use a "mock" servlet container which can exercise the servlet under control of a local program, with no HTTP involved.
Can you explain a bit more about what you want to do, and why it would be useful to you?

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Chandra Bairi
Ranch Hand

Joined: Sep 12, 2003
Posts: 152
Yes exactly I just wanted to know if we can exexcute the servlet as a mock one without the Http. can you tell me how we do it. I was asked in a interview this question. Answer please.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036
Servlets are designed to operate inside a "servlet container" which provides a number of functions such as creating request and response objects, maintaining a servlet context, etc... Therefore if you want to completely exercise a servlet with realistic request and response it has to be in some sort of a servlet container. For complete realism, it should provide the complete servlet API.
If your servlet has a whole bunch of methods that you need to debug, maybe you should rethink your architecture and move those methods into "helper classes" where they can be debugged outside the servlet environment.
(Yes, I know, I say that alot )
I agree. Here's the link:
subject: Can servlet be executed differently
It's not a secret anymore!