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

Abstract servlet

sam liya
Ranch Hand

Joined: Nov 25, 2008
Posts: 1204
there is a abstract servlet in my project and made the database connection in init() method.
.in my subclass servlet extend the abstract servlet and overide th init() method.
and call super class init() method.
but if i remove calling super.init() it gives an ERROR.
what is the reason?
when extending my servlet to the super servlet it should call super init() method?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

aruna sameera wrote:
when extending my servlet to the super servlet it should call super init() method?


Not required . what error you are getting ? . and better to post your base servlet code using the code tag.
sam liya
Ranch Hand

Joined: Nov 25, 2008
Posts: 1204
this is my abstract servlet



This is my sub seervlet class





[/code]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

It is required if you want your init code to be run in Connector. If you override a method it replaces the method it overrides, if you still want to call the original method call super.themethodName() in the overridden method.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

that is because of your Connection is null , since the DB Connection logic is inside your BaseServlet's[Connector] init().
so, you need to call the method
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Hi there,

What do you thing that can be null in your code with the super.init() commented? Why it works when you decomment it? (I don't know if decomment exist but I think all of you understand :P )

The exception is quite logic if you think about it!
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Oh, seetharaman, answered to you.

Other thing I have seen is that you have an abstract class with no abstract declarations... anyway, here the problem has nothing to do with being abstract servlet or "normal" one.
 
 
subject: Abstract servlet