Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract servlet

 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my abstract servlet



This is my sub seervlet class





[/code]
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic