answersLogoWhite

0


Best Answer

Why do we need a Session?

When one page needs to share information with another, the scope of the data broadens beyond processing a single request. This is because, when a response gets committed, all the data that was held in the request that generated that response is destroyed. So, if you want that data in another page, you will be looking at a blank request object with no data in it. When such a need arises, you must send the data from one page to the server and from the server to the next requested page, whether it be the same page or another page altogether. There are several ways to share state information between requests. However, the primary or the easiest way is to use sessions.

How Do Sessions Work?

The container generates a session ID. When you create a session, the server saves the session ID on the client's machine as a cookie. If cookies are turned off then it appends the ID in the URL. On the server, whatever you add to the session object gets placed in server memory-very resource intensive. The server associates that object in memory with the session ID. When the user sends a new request, the session ID is sent too. The server can then match the objects in its memory with that session ID. This is how we maintain client state.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

AnswerBot

3d ago

In servlet programming, a session is a way to maintain state between multiple requests from the same client. There are several ways to track sessions in servlet programming, including cookies, URL rewriting, and hidden form fields. Cookies are the most commonly used method, where a unique identifier is stored on the client's browser to associate subsequent requests with the same session. URL rewriting involves appending session IDs to URLs, while hidden form fields store session IDs in HTML forms.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is a session What are the different ways of session tracking in servlet programming?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Information Science

How do you dynamically identify the jsp in servlet?

You can dynamically identify the JSP file in a servlet by using the request URL or request parameters to determine which JSP to forward the request to. You can also store necessary information in session attributes or external configurations to help determine the appropriate JSP to display. Finally, you can use a servlet mapping or URL pattern to route requests to different JSP files based on the URL.


Set and get session attributes syntax in servlets and java script?

Setting and getting session attributes is fairly easy. It is the same in both Servlets and JSPs with one exception. In a JSP, you already have access to the session object, and you do not have to declare it. In a Servlet, you must get the session like this: javax.servlet.http.HttpSession session = request.getSession(); Once you have done that, you can set a session object like this: session.setAttribute("name","value"); To retrieve the value, do this: String foo = (String) session.getAttribute("name"); A couple of things to keep in mind: * The second parameter in the setAttribute method is an Object, not a String. When you retrieve the value, you have to cast it. In the example above, I am casting it to a String. * If you try to perform a getAttribute on a session attribute that does not exist, or was not set, it will return a null. * Session attributes are not available using JavaScript. You can not set or get an attribute in JavaScript. * You do NOT need to do the 'session = request.getSession() in a JSP. It is only necessary in a Servlet.


What is a different way of saying information session?

Informational meeting or briefing.


What is the abbreviation for Session?

The common abbreviation for "Session" is "Sess."


What is servlet context?

The ServletContext is an object provided by the servlet container that allows servlets to communicate with the container. It represents the configuration and environment of a web application and provides access to resources such as parameters, attributes, and initialization parameters. Servlets can use the ServletContext to perform tasks like accessing resources, logging events, and managing session persistence.

Related questions

Session tracking in servlet?

Each web application contains a Session that can contain data that can be commonly made available to all the parts of the web application. The Session can be accessed from both the JSP and the Servlet. Ex: The servlet contains references to the HttpRequest object. So to access the session you can do so as below: HttpSession session = request.getSession();


What is servlet and why it is used?

servlet is a small program which run on serverside,and it can not be downloaded at client side. java servlets dynamically extends the functionalities of a web server. main use is: session tracking: no of users (unique) visited u'r website. in order to use cookies..


How many scope are there in servlet?

The two scopes are: Request & Session


How is statelessness of http overcome to run e-commerce applications on web?

it can be overcome by implementing session tracking & management in the running program on the server side. There are four solutions 1. Cookies, 2. Hidden from field, 3. URL rewriting and 4.Servlet Session API


10 Explain the term session in server side programming approach What is the main benefit from implementing the session?

explain the term session in server side programming approach


What is used to find logical errors in programming?

Checking the output you get for different inputs; checking the source code; carrying out a debugging session.


What is session in jsp?

Session in the JSP and Servlet context refers to an instance of the HttpSession object that contains all the information about the current user session with the web application. This can be used as a cache or temporary storage area to store values that might be required across the application.


Set and get session attributes syntax in servlets and java script?

Setting and getting session attributes is fairly easy. It is the same in both Servlets and JSPs with one exception. In a JSP, you already have access to the session object, and you do not have to declare it. In a Servlet, you must get the session like this: javax.servlet.http.HttpSession session = request.getSession(); Once you have done that, you can set a session object like this: session.setAttribute("name","value"); To retrieve the value, do this: String foo = (String) session.getAttribute("name"); A couple of things to keep in mind: * The second parameter in the setAttribute method is an Object, not a String. When you retrieve the value, you have to cast it. In the example above, I am casting it to a String. * If you try to perform a getAttribute on a session attribute that does not exist, or was not set, it will return a null. * Session attributes are not available using JavaScript. You can not set or get an attribute in JavaScript. * You do NOT need to do the 'session = request.getSession() in a JSP. It is only necessary in a Servlet.


What time tracking software is available?

There are many time tracking programs available. Among them are Time Doctor, Get Harvest, Zoho Projects, TimeCamp, Time Sheet Reporter, and Replicon.


Why is opening session of the house each term quite different from the opening session of the senate?

They have opening sessions because they are different branches of government.


What does servlet session API means?

The Servlet Session API refers to the documentation on the list of methods available in the HttpSession class that is used for Session ManagementThe HttpSession object is very powerful and has many features. Before we dig deep into the world of Sessions, let us take a look at the important methods they have so that we can use them effectively.• getAttribute(java.lang.String name) - Returns an Object associated with that name that was stored in the session object.• getAttributeNames() - Returns an Enumeration object that lists the names of the objects stored in the session object.• getCreationTime() - Returns a long containing the date stamp of creation.• getId() - Returns the id of the session as a String representing the unique identifier assigned to this session.• getLastAccessedTime() - Returns a long containing the date stamp of the last time the session was accessed.• getMaxInactiveInterval() - Returns an integer representing the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses.• invalidate() - This destroys a session. It can't be referenced after this method has been called.• isNew() - This tells you whether the client knows about the session. In other words, the has session been created by the server, but the client hasn't acknowledged receiving the session ID yet.• removeAttribute(java.lang.String name) - This removes an attribute. It deletes it from the session object.• setAttribute(java.lang.String name, java.lang.Object value) - You use this method to add objects to a session.• setMaxInactiveInterval(int interval) - Specifies the time, in seconds, between client requests before the servlet container will invalidate this session.• getValue(java.lang.String name) - Returns an Object associated with that name that was stored in the session object. As of Version 2.2, this method is replaced by getAttribute(). The getAttribute() method will be on the exam, not this one, but it is here for completeness.• getValueNames() - Returns a String array with a list of names associated with the objects added to a given session. As of Version 2.2, this method is replaced by getAttributeNames(). The getAttributeNames() method will be on the exam, not this one, but it is here for completeness.• putValue(java.lang.String name, java.lang.Object value) - You use this method to add objects to a session. This has been deprecated. As of Version 2.2, this method is replaced by setAttribute(java.lang.String, java.lang.Object). The setAttribute() method will be on the exam, not this one, but it is here for completeness.• removeValue(java.lang.String name) - This removes a value, but retains an attribute name in the session. The name is valid but the object is null. This has been deprecated. As of Version 2.2, this method is replaced by removeAttribute(). The removeAttribute() method will be on the exam, not this one, but it is here for completeness.


How much is tattoo removal on average?

It cost $400 per session (a session is about 15 minutes). Each session will also be different depending on how large and or small the tattoo actually is.