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

Sharing method between servlets

shaf maff
Ranch Hand

Joined: Sep 07, 2008
Posts: 180
Hi Guys

I have the following method in my servlet:

I am now working on another servlet which will also be using this method. I want to know the best way I can share it between both servlets. I was thinking of creating a final class and make the method a static method. Is this a good way of dealing with this issue ?
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

You should move that part (only, code which can be reused and not the things usually go in servlets like setting the content type etc.. ) in to a separate class and let the servlets (or other components) call it, in that way any changes for that can be made easily later.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
sudhir nim
Ranch Hand

Joined: Aug 29, 2007
Posts: 212

You can have a BaseServlet and move the method to it, than let your other servlets extend it.


[Servlet tutorial] [Servlet 3.0 Cook Book]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sharing method between servlets