Is there any way to get an object which will be there throughout the session from ServletContext object??
Use the request. getSession() method of the HttpServletRequest object. If a session object is already associated with the client request, this method returns it.
Creating or Accessing a Session To create a new session or gain access to an existing session, use the HttpServletRequest method getSession(), as shown in the following example: HttpSession mySession = request. getSession();
ServletConfig object is obtained by getServletConfig() method. ServletContext object is obtained by getServletContext() method.
There's only one ServletContext for an entire web app, and all the parts of the web app share it. But each servlet in the app has its own ServletConfig. The Container makes a ServletContext when a web app is deployed, and makes the context available to each Servlet and JSP (which becomes a servlet) in the web app.
No, it's not possible to get the session from the ServletContext.The point of the ServletContext is to get application scope attributes rather than session scope.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With