91-9990449935 0120-4256464 |
4) HttpSession interfaceIn such case, container creates a session id for each user.The container uses this id to identify the particular user.An object of HttpSession can be used to perform two tasks:
How to get the HttpSession object ?The HttpServletRequest interface provides two methods to get the object of HttpSession:
Commonly used methods of HttpSession interface
Example of using HttpSessionIn this example, we are setting the attribute in the session scope in one servlet and getting that value from the session scope in another servlet. To set the attribute in the session scope, we have used the setAttribute() method of HttpSession interface and to get the attribute, we have used the getAttribute method. index.htmlFirstServlet.javaSecondServlet.javaweb.xml
download this example (developed using Myeclipse IDE)
download this example (developed using Eclipse IDE) download this example (developed using Netbeans IDE) |