Can we override the init() & destroy() in case of serveltjsp

Posted on 2008-11-11
Last Modified: 2013-11-24
Can we override the init() & destroy() in case of servelt/jsp?
Question by:Asheesh_Kumar
    LVL 15

    Accepted Solution

    Sure you do. They are supposed to be overridden.
    LVL 15

    Expert Comment

    Remember that when overriding init, include super.init(config) in it as well.
    LVL 6

    Assisted Solution

    The answer is possibly. The init() method gives you a chance to initialize your servlet before handling any client requests. So if you have initialization code (like getting a database connection or registering yourself with other objects), then you'll override the init() method in your servlet class.

    Container calls destroy method to give the servlet  a chance to clean up before the servlet is killed. Like init it's called only once. So rarely you would want to override destroy() method but you can.
    LVL 6

    Expert Comment

    I gave the answer. Thanx
    LVL 6

    Expert Comment

    it's ok, I didn't understand
    LVL 6

    Expert Comment

    What kind of answer is? Sure you do. They are supposed to be overridden.

    The only methods to be supposed overridden are doGet or doPost.

    I gave a complete answer  

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Suggested Solutions

    Title # Comments Views Activity
    Problem to setup 18 66
    hasOne  challenge 59 63
    count11 challenge 6 32
    drawing animated level bar based on numbers 3 41
    Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
    How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now