Java - Sessions in a JSP page

by
Jeremy Canfield |
Updated: March 23 2022
| Java articles
You may want to first read about the difference between a session and a cookie.
This assumes you have created your first dynamic web project in Eclipse. There are a few different ways to create a session. You can use cookies, URL rewriting, or SSL.
Adding the following markup inside of the body tags of a JSP page will display session ID, if a session has been established.
${pageContext.session.id}
In this example, the session ID was obtained. This is pratical if you want a global session for your entire site. If you need to create and destroy sessions as users request certain parts of your application, it makes more sense to create a unique session in your Java code.
Did you find this article helpful?
If so, consider buying me a coffee over at