• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invoking a Servlet

 
Samuel Lugo
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So using the URL and URLConnection classes would work?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic