This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 12761
    
    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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Invoking a Servlet
 
Similar Threads
Capturing Form Data
javascript, servlets and SVG
Export in Excel
How can I change the sdk version of Websphere 4 if I already install it
Is there any way to get Servlet Init Parameter using EL?