Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

With respect to servlets  RSS feed

 
Geeta Ramasami
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is it possible to have any number of methods apart from doGet and doPost in servlets?If so how can i call that method directly from any java class.Do i need to open a url connection to servlet and call it from doGet or doPost or can i create an instance of the servlet just like any other java class and invoke the method?If that method returns an object will i have to make my servlet class as serializable?
Regards
Geeta
 
Andy Bowes
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that a better solution would be to create the methods that you want to add to the servlet in aother plain Java class file and then invoke these methods from both the servlet and anywhere else that you need the functionality.
Servlets are designed to reply to HttpRequests, keep the design pure and ensure that this is all they do.
Hope this helps
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't create an instance of a servlet class outside of a servlet container and expect it to behave right. A servlet container provides all sorts of functions to your servlet class.
As Andy observes, the best solution is to create helper classes that you can test outside the servlet environment.
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!