wood burning stoves 2.0*
The moose likes Servlets and the fly likes Invoking Servlets Outside a Webapp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Invoking Servlets Outside a Webapp" Watch "Invoking Servlets Outside a Webapp" New topic
Author

Invoking Servlets Outside a Webapp

Jason Morris
Greenhorn

Joined: Nov 17, 2004
Posts: 2
From the "Hammering a nail with a screwdriver dept."

Is it possible to invoke a servlet without invoking a servlet container (like Tomcat)?

-JM


Jason Morris<br />Morris Technical Solutions<br />consulting@morristechnicalsolutions.com<br /><a href="http://www.morristechnicalsolutions.com" target="_blank" rel="nofollow">www.morristechnicalsolutions.com</a><br />fax/phone: 503.692.1088
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30392
    
150

Jason,
Do you mean you want the servlet to run by itself? You could pass it a mock request and response. But then it would function as a regular class and not a servlet. What are you trying to accomplish?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jason Morris
Greenhorn

Joined: Nov 17, 2004
Posts: 2
Hi Jeanne,

>> Do you mean you want the servlet to run by itself?
>> You could pass it a mock request and response.

Hi Jeanne,
I'm actually cross-posting for a fellow developer from the Portland Java Users Group. Essentially, he is doing what you describe -- trying to treat a servlet as a class, but not as you would expect when using a mock req/res approach -- usally (my understanding) is that it is for testing.

He actually wants the servlet to do useful work (processing a some data or something via an Ant script -- it gets convoluted to my way of thinking.. ) anyway.. I was just wondering if there was any practical examples of this being done -- and hence my hammering a nail with a screwdriver analogy.

Cheers,
Jason
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Servlets depend on the servlet container for a LOT of services, so faking the servlet container environment would be a waste of time.
Instead, move all the functionality into a "helper" class that can run in both the servlet container and normal application environment. Incidently that is a great way to test and debug during servlet development.
For example, the request getParameterMap() method returns all of the request parameter values in String[] keyed by parameter name. You can easily create an identical map as input to a method in a non-servlet environment.
Bill
 
wood burning stoves
 
subject: Invoking Servlets Outside a Webapp