Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session object using ServletContext

Tags:

java

servlets

Is there any way to get an object which will be there throughout the session from ServletContext object??

like image 817
user241924 Avatar asked Jan 16 '10 07:01

user241924


People also ask

Which method is used for session 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.

How do you create a session using HTTP session object?

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();

Which is the correct way to get ServletContext object?

ServletConfig object is obtained by getServletConfig() method. ServletContext object is obtained by getServletContext() method.

How many ServletContext object is available for the entire web application?

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.


1 Answers

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.

like image 146
Taylor Leese Avatar answered Sep 23 '22 03:09

Taylor Leese