Sometime while developing web application it is necessary to interact with the different values of the Session object. In this example we will explore the different values of the Session object and then learn how to use it in our programming code.
You will learn how to find all the session related information like:
Here is the sample code for HttpSessionDisplay.java:
import java.io.*;
|
Here is the mapping of class file in web.xml.
| <servlet> <servlet-name>HttpSessionDisplay</servlet-name> <servlet-class>HttpSessionDisplay</servlet-class> </servlet> <servlet-mapping> <servlet-name>HttpSessionDisplay</servlet-name> <url-pattern>/HttpSessionDisplay</url-pattern> </servlet-mapping> |
Run this example by this url: http://localhost:8080/CodingDiaryExample/HttpSessionDisplay
Output:
In case of first time accessing of servlet the following session value will be displayed

In case of preexist session if user accessed the servlet then the following session value will be displayed.

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Display session value Using Servlet View All Comments
Post your Comment