Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Servlets and the fly likes one servlet question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "one servlet question" Watch "one servlet question" New topic
Author

one servlet question

ashish kulkarni
Ranch Hand

Joined: Aug 15, 2002
Posts: 130
Hi,
I have to write a servlet which will be a base servlet for all servlets in my applications.
I have a class called GetConnection which gets the connection from servletcontext depending upon some parameters in the session, so i have go send servletcontext, and session to this class.
now the question is should i create the instance of this class in init method of the servlet or define a seperate method and create the instance of that class from doget or dopost method of the child servlet,(this servlet will extend the base servlet).
i have this doubt because if i create the instance of this getconnection class in init method, it will be in memory for the full life cycle of servlet(i.e. untill i stop the app server).
so if i extend this base servlet for other 100 child servlets, then there will be 100 instance of getconnection for life cycle of servlet.
so am i thinking in the right way???
any suggestions


A$HI$H
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Just a thought!.(if i understand you Q clearly)
Instead of thinking about 100 child servlets and one base servlet.Try to think abt having one main controllerServlet and have 100 classes derived with UML.
Try to see how velocity or struct framework is doing this.
Regards
Balaji


Spritle Software Blogs
 
GeeCON Prague 2014
 
subject: one servlet question