Logo

Navigation
  • Home
  • Services
    • ERP Solutions
    • Implementation Solutions
    • Support and Maintenance Solutions
    • Custom Solutions
    • Upgrade Solutions
    • Training and Mentoring
    • Web Solutions
    • Production Support
    • Architecture Designing
    • Independent Validation and Testing Services
    • Infrastructure Management
  • Expertise
    • Microsoft Development Expertise
    • Mobile Development
    • SQL Server Database and BI
    • SAP BI, SAP Hana, SAP BO
    • Oracle and BI
    • Oracle RAC
  • Technical Training
    • Learn Data Management
      • Business Intelligence
      • Data Mining
      • Data Modeling
      • Data Warehousing
      • Disaster Recovery
    • Learn Concepts
      • Application Development
      • Client Server
      • Cloud Computing Tutorials
      • Cluster Computing
      • CRM Tutorial
      • EDI Tutorials
      • ERP Tutorials
      • NLP
      • OOPS
      • Concepts
      • SOA Tutorial
      • Supply Chain
      • Technology Trends
      • UML
      • Virtualization
      • Web 2.0
    • Learn Java
      • JavaScript Tutorial
      • JSP Tutorials
      • J2EE
    • Learn Microsoft
      • MSAS
      • ASP.NET
      • ASP.NET 2.0
      • C Sharp
      • MS Project Training
      • Silverlight
      • SQL Server 2005
      • VB.NET 2005
    • Learn Networking
      • Networking
      • Wireless
    • Learn Oracle
      • Oracle 10g
      • PL/SQL
      • Oracle 11g Tutorials
      • Oracle 9i
      • Oracle Apps
    • Learn Programming
      • Ajax Tutorial
      • C Language
      • C++ Tutorials
      • CSS Tutorial
      • CSS3 Tutorial
      • JavaScript Tutorial
      • jQuery Tutorial
      • MainFrame
      • PHP Tutorial
      • VBScript Tutorial
      • XML Tutorial
    • Learn Software Testing
      • Software Testing Types
      • SQA
      • Testing
  • Career Training
    • Career Improvement
      • Career Articles
      • Certification Articles
      • Conflict Management
      • Core Skills
      • Decision Making
      • Entrepreneurship
      • Goal Setting
      • Life Skills
      • Performance Development
      • Personal Excellence
      • Personality Development
      • Problem Solving
      • Relationship Management
      • Self Confidence
      • Self Supervision
      • Social Networking
      • Strategic Planning
      • Time Management
    • Education Help
      • Career Tracks
      • Essay Writing
      • Internship Tips
      • Online Education
      • Scholarships
      • Student Loans
    • Managerial Skills
      • Business Communication
      • Business Networking
      • Facilitator Skills
      • Managing Change
      • Marketing Management
      • Meeting Management
      • Process Management
      • Project Management
      • Project Management Life Cycle
      • Project Management Process
      • Project Risk Management
      • Relationship Management
      • Task Management
      • Team Building
      • Virtual Team Management
    • Essential Life Skills
      • Anger Management
      • Anxiety Management
      • Attitude Development
      • Coaching and Mentoring
      • Emotional Intelligence
      • Stress Management
      • Positive Thinking
    • Communication Skills
      • Conversation Skills
      • Cross Culture Competence
      • English Vocabulary
      • Listening Skills
      • Public Speaking Skills
      • Questioning Skills
    • Soft Skills
      • Assertive Skills
      • Influence Skills
      • Leadership Skills
      • Memory Skills
      • People Skills
      • Presentation Skills
    • Finding a Job
      • Etiquette Tips
      • Group Discussions
      • HR Interviews
      • Interview Notes
      • Job Search Tips
      • Resume Tips
      • Sample Resumes
 

Working with JSP Sessions

By Exforsys | on April 18, 2010 |
JSP Tutorials

Working with JSP Sessions

In this JSP tutorial, you will learn about JSP session object methods, getCreationTime, getLastAccessedTime, getId, invalidate(), getMaxInactiveInterval, setMaxInactiveInterval(), removeAttribute(String name) and setAttribute(String, object).

This section details the syntax, usage, example and explanation of more session object methods, such as:

  • getCreationTime
  • getLastAccessedTime
  • getId
  • invalidate()
  • getMaxInactiveInterval
  • setMaxInactiveInterval()
  • removeAttribute(String name)
  • setAttribute(String, object)

getCreationTime:

The getCreationTime method of session object is used to return the session created time. The returned time value would be in milliseconds, the time value is midnight January 1, 1970 GMT.

General syntax of getCreationTime of session object is as follows:


session.getCreationTime()

The above method returns value of time in milliseconds.

For example:


out.println("
Created Time of Session is: " + session.getCreationTime());

The above statement would display


Created Time of Session is:
974154073972

The above output depicts the creation time of session since January 1, 1970 GMT in milliseconds.

getLastAccessedTime:

The getLastAccessedTime method of session object is used to return the latest time of the client request associated with the session. By using this method, it is possible to determine the last time the session was accessed before the current request. The returned time value would be in milliseconds and the time value is since midnight January 1, 1970 GMT.

General syntax of getLastAccessedTime of session object is as follows:


session.getLastAccessedTime()

The above method returns the value of time in milliseconds.

For example:


out.println("
Last Accessed Time of Session is: " + session.getLastAccessedTime());

The above statement would display:


Last Accessed Time of Session is:
953044321813

The above output depicts the last time the session was accessed before the current request since January 1, 1970 GMT in milliseconds.

getId:

The getID method of session object is used to return the unique identifier associated with the session.

General syntax of getID of session object is as follows:


session.getId()

For example:


out.println("
The Session ID is: " + session.getId());

The above statement would display


The Session ID is:
A1BQWTBBBBBBKSY2HJKQBBB

The above statement denotes the unique identifier associated with the current session.

invalidate():

invalidate method of session object is used to discard the session and releases any objects stored as attributes. This method helps to reduce memory overhead and achieves improvement in performance. It is always a good practice to explicitly remove or invalidate sessions using session.invalidate() method.

General syntax of invalidate of session object is as follows:


session.invalidate()

getMaxInactiveInterval:

The getMaxInactiveInterval method of session object is used to return the maximum amount of time the JRun keeps the session open between client accesses. This returns the maximum amount of time, in seconds, that a session can be inactive before it is deleted. The returned value of time is in seconds. Thus, by using this method the user determines how long it will take a session for it to time out. The default timeout period for sessions defined by the servlet container is determined using the getMaxInactiveInterval method. The returned value from this method is seconds and thus, an integer.

General syntax of getMaxInactiveInterval of session object is as follows:


session.getMaxInactiveInterval()

The above method returns value of time in seconds.

For example:


out.println("
Maximum Inactive Interval of Session in Seconds is : " +session.getMaxInactiveInterval());

The above statement would display


Maximum Inactive Interval of Session in Seconds is :
2000

The above denotes the time in seconds.

setMaxInactiveInterval():

This is another setMaxInactiveInterval() method that a developer can use to set the timeout explicitly for each session. A user can use this method to set the default timeout.

General syntax of setMaxInactiveInterval of session object is as follows:


session.setMaxInactiveInterval(
time)

In the above the time given in parameter is in seconds.

For example:


session.setMaxInactiveInterval(
600);

In the above statement, the inactivity period for the session would be set to 10minutes.The parameter 600 given in the method would be in seconds.

removeAttribute(String name):

The removeAttribute method of session object is used to remove the attribute and value from the session.

General syntax of removeAttribute of session object is as follows:


session.removeAttribute(String)

For example:


session.removeAttribute("exforsys");

Example exforsys given in parameter of removeAttribute method is a string.

setAttribute(String, object):

The setAttribute method of session object is used to set the object to the named attribute. This method is used to write an attribute and value to the session. If the attribute does not exist, then it is created and then the object is associated with this.

General syntax of setAttribute of session object is as follows:


session.setAttribute(String, object)

For example:


String exforsys = request.getParameter("test"); session.setAttribute("test", exforsys);

In the above example, the first parameter passed to the method setAttribute test denotes a string and the second parameter exforsys denotes the object. By passing these to the setattribute method, the object exforsys is set with the string test.

« « Focus Facilitated Discussion
Facilitator Tips » »

Author Description

Avatar

Editorial Team at Exforsys is a team of IT Consulting and Training team led by Chandra Vennapoosa.

Free Training

RSSSubscribe 392 Followers
  • Popular
  • Recent
  • JSP Introduction

    April 27, 2007 - 0 Comment
  • JSP Out Object

    May 5, 2007 - 0 Comment
  • JSP Environment Setup

    April 27, 2007 - 0 Comment
  • JSP Application Object

    May 5, 2007 - 0 Comment
  • JSP Tags

    April 27, 2007 - 0 Comment
  • JSP Directives

    April 27, 2007 - 0 Comment
  • JSP Page Directive

    April 28, 2007 - 0 Comment
  • JSP Directive Tag and Scriptlet tag

    April 28, 2007 - 0 Comment
  • Sell CC Fresh Visa,MasterCard,American Express,Discover All Country

    May 3, 2007 - 0 Comment
  • JSP Request Object

    May 7, 2007 - 0 Comment
  • JSP Response Object

    May 8, 2007 - 0 Comment
  • JSP Request Object

    May 7, 2007 - 0 Comment
  • JSP Out Object

    May 5, 2007 - 0 Comment
  • JSP Application Object

    May 5, 2007 - 0 Comment
  • JSP Implicit and Session Objects

    May 4, 2007 - 0 Comment
  • Sell CC Fresh Visa,MasterCard,American Express,Discover All Country

    May 3, 2007 - 0 Comment
  • JSP Architecture

    April 29, 2007 - 0 Comment
  • JSP Page Directive

    April 28, 2007 - 0 Comment
  • JSP Directive Tag and Scriptlet tag

    April 28, 2007 - 0 Comment
  • JSP Introduction

    April 27, 2007 - 0 Comment

Exforsys e-Newsletter

ebook
 

Related Articles

  • JSP Response Object
  • JSP Request Object
  • JSP Out Object
  • JSP Application Object
  • JSP Implicit and Session Objects

Latest Articles

  • Project Management Techniques
  • Product Development Best Practices
  • Importance of Quality Data Management
  • How to Maximize Quality Assurance
  • Utilizing Effective Quality Assurance Strategies
  • Sitemap
  • Privacy Policy
  • DMCA
  • Trademark Information
  • Contact Us
© 2023. All Rights Reserved.IT Training and Consulting
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT