Sei sulla pagina 1di 3

7/15/13

What is JSESSIONID in J2EE Web application - JSP Servlet?

Javarevisited
Blog about Java Program Tutorial Example How to, Unix Linux commands, Interview Questions, FIX Protocol, Tibco RV tutorials, Equities trading system, MySQL

Java 6
S UNDA Y , A UGUS T 12, 2012

Web Application

Java Java

Java Applications
Loading

What is JSESSIONID in J2EE Web application - JSP Servlet?


What is JSESSIONID in JSP Servlet J S E S S I O N I Dis a cookie generated by Servlet container like Tomcat or Jetty and used for session management in J2EE web application for http protocol. Since HTTP is a stateless protocol there is no way for Web Server to relate two separate requests coming from same client and Session management is the process to track user session using different session management techniques like C o o k i e sand URL Rewriting. If Web server is using cookie for session management it creates and sends J S E S S I O N I Dcookie to the client and than client sends it back to server in subsequent http requests. J S E S S I O N I Dand session management is a not only a popular Servlet interview question but also appear in various JSP interviews. Along with What is J S E S S I O N I Dinterviewer are also interested in when and how J S E S S I O N I Dis created in Servlet and JSP which we will see in next section.

Recent Posts

When J S E S S I O N I Dcreated in Web application? In Java J2EE application container is responsible for Session management and by default uses Cookie. When a user first time access your web application, session is created based upon whether its accessing HTML, JSP or Servlet. if user request is served by Servlet than session is created by calling r e q u e s t . g e t S e s s i o n ( t r u e )method. it accepts a boolean parameter which instruct to create session if its not already existed. if you call r e q u e s t . g e t S e s s i o n ( f a l s e )then it will either return n u l lif no session is associated with this user or return the associated H t t p S e s s i o nobject. If H t t p R e q u e s tis for JSP page than Container automatically creates a new Session with JSESSIONID if this feature is not disabled explicitly by using page directive % @p a g es e s s i o n = " f a l s e "% > .Once Session is created Container sends J S E S S I O N I Dcookie into response to the client. In case of HTML access, no user session is created. If client has disabled cookie than Container uses URL rewriting for managing session on which j s e s s i o n i dis appended into URL as shown below: https://localhost:8443/supermart/login.htm;j s e s s i o n i d =1A530637289A03B07199A44E8D531427 When HTTP session is i n v a l i d a t e d ( ) ,mostly when user logged off, old J S E S S I O N I Ddestroyed and a new J S E S S I O N I Dis created when user further login.

How to monitor HTTP request to check JSESSIONID


You can check value of J S E S S I O N I Dcoming in as cookie by monitoring HTTP request. If you are running Tomcat Server in NetBeans IDE in your development environment than you can use HTTP Server Monitor to check http requests. You just need to enable it while starting Tomcat Server form Netbeans. After than with each request you can see all details like request headers, session, cookies etc in HTTP Server monitor screen. If you look on J S E S S I O N I Dcookie it will look like: cookie J S E S S I O N I D =1A530637289A03B07199A44E8D531427 You can also enable http request and response in Client side by using tools like ethereal or Wireshark . This tool can monitor all http traffic from and to your machine and by looking on request data you can see J S E S S I O N I Dcookie and its value. That's all on What is J S E S S I O N I Dand How JSESSIONID is created inside J2EE application. We have seen that both Servlet and JSP can be responsible for Session creation but its done by Container. you can retrieve value of S e s s i o n I D which is represented by J S E S S I O N I Dcookie when you call r e q u e s t . g e t S e s s i o n ( ) .Session management in web applications are complex topic especially when it comes to clustering and distributed session. On the other hand J S E S S I O N I Dis one of those basics which as J2EE web application developer you should be aware of. Other JSP and Servlet tutorial from Javarevisited Blog Difference between include directive and include action Top 10 Spring interview question and answer for J2EE programmer Difference between get and load in hibernate Top 10 Struts interview question and answer in Java How to get ServletContext object in Spring controller How to setup JDBC connection pool using Spring

Follow Us Follow @javinpaul

Recommendd Books Java Programming and Design Pattern Spring Framework Subscribe by email: Subscribe By Javin Paul

javarevisited.blogspot.in/2012/08/what-is-jsessionid-in-j2ee-web.html

1/3

7/15/13

What is JSESSIONID in J2EE Web application - JSP Servlet?


Subscribe To This Blog Free

Posts Comments
Please share with your friends if like this article Followers

Posted by Javin Paul at 6:38 AM Labels: interview questions, jsp-servlet

1 comment:
Anonymous said... I hardly need someone able to decode a JSessionID to get the 'timeTag' in it (date of connection) contact ovny29@free.fr in France urgent and important June 13, 2013 at 3:39 PM

Post a Comment
E n t e ry o u rc o m m e n t . . .

Java J2EE Developers Java Applications Download Java JDK


Blog Archive 2013 (97) 2012 (218) December (52)

Comment as: Google Account Publish Preview

November (8) October (15) September (8) August (9) Top 10 JDBC Best Practices for Java Programmer

Newer Post Subscribe to: Post Comments (Atom)

Home

Older Post

How to delete empty files directories in Unix Linu... How to Convert Collection to String in Java Spri... How to write parametrized Generic class and method... What is JSESSIONID in J2EE Web application JSP S... Best Practices to write JUnit test cases in Java How to format String in Java String format Examp... How to get environment variables in JavaExample ... 5 ways to convert InputStream to String in Java July (9) June (12) May (10) April (14) March (28) February (18) January (35) 2011 (145) 2010 (33)

References Java API documentation JDK 6 Spring framework doc Struts

javarevisited.blogspot.in/2012/08/what-is-jsessionid-in-j2ee-web.html

2/3

7/15/13

What is JSESSIONID in J2EE Web application - JSP Servlet?


ANT Maven JDK 7 API MySQL Linux Eclipse Copyright by Javin Paul 2012. Powered by Blogger.

About Me

Privacy Policy

javarevisited.blogspot.in/2012/08/what-is-jsessionid-in-j2ee-web.html

3/3

Potrebbero piacerti anche