Using sessions in java servlet?

Posted on 2006-04-24
Last Modified: 2010-04-01

Could anyone demonstrate how to delete a session within servlet's.

I would also like to timeout sessions, to achieve this would I need to set a timeinterval value web.xml file of tomcat?

And finally, I am using tomcat and passing a javabean between the servlet and jsp page.

My text book says the javabean class declaration should implement Serializable. Is this correct with all javabean classes?

Thank you
Question by:AntoniRyszard656
    1 Comment
    LVL 6

    Accepted Solution

    You have a method HttpSession.invalidate() to teminate your session.

    Session timeout in web.xml
              <session-timeout>30</session-timeout><!-- time in minutes -->

    Javabeans require to implement Serializalbe interface. Its a marker interface, means it doesnt have any methods in it.
    The classes that implement Serializable interface, the objects of that class can save its state.
    This is helpful when u are transfering objects thru network.
    But its a good practice that your javabean classes implement Serializable, whether or not you send them thru network.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    761 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

    14 Experts available now in Live!

    Get 1:1 Help Now