aspose file tools*
The moose likes Servlets and the fly likes Invoking a Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Invoking a Servlet" Watch "Invoking a Servlet" New topic
Author

Invoking a Servlet

Samuel Lugo
Greenhorn

Joined: Feb 28, 2005
Posts: 24
Hello,

Is it possible to invoke a servlet from another Java class that is not a servlet? If so, what would be the best way to go about doing that?

Thanks in advance for the assistance.

lugos
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

It depends if you want it to run as a servlet or just another class. If you want it to run as a servl;et, you'll want to put it in a container and call it via a url connection. Otherwise, just create a fake implementation of the request and response interfaces and go for it!
Samuel Lugo
Greenhorn

Joined: Feb 28, 2005
Posts: 24
So using the URL and URLConnection classes would work?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
Note that if you open a URLConnection with a URL that starts "http://" what you get is actually a HttpURLConnection (in the java.net package). There is where you find methods such as setRequestMethod() which are probably going to be useful when talking to your servlet.
Bill
 
jQuery in Action, 2nd edition
 
subject: Invoking a Servlet