answersLogoWhite

0

What is session in java?

Updated: 8/10/2023
User Avatar

Wiki User

13y ago

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

Wiki User

14y ago

A lasting connection between a user (or user agent) and a {peer}, typically a {server}, usually involving the exchange of many packets between the user's computer and the server.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is session in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you clear session table values using java coding?

You can use session.removeValue() method. by passing the string identifier of the value you need to remove you can do it. or you can use session.invalidate() if you want to destroy the whole session and its values.


What are topics covered in advanced Java?

Some of the concepts covered in Advanced Java are:MultithreadingException HandlingRemote Method Invocation - RMIGarbage Collectionetc


What is a stateless session beans?

A stateless session bean is a type of enterprise bean in Java EE that doesn't maintain any conversational state with clients. Each client request is treated independently, and the server can choose any available instance of the stateless session bean to handle the request. Statelessness allows for efficient use of resources and parallel processing since the server doesn't have to keep track of the state of each client.


What Indonesian island is Jakarta on?

java


Does Visual Java plus plus and Java Builder is different from the Java language?

Yes!Visual Java plus plus and Java Builder is different from the Java language?


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 are the different java technologies?

There are several types of Java technology. Some examples of Java software are Java ME, Java EE, Java SE, and Java Card. Java made the JAVA development kit for those that develop in Java. There is also Java Virtual machine and some class libraries. Java is also famous for its languages like Clojure, Beanshell, Groovy, Gosu, Rhino, Kotlin, JRuby, Scala, and Jython.


Small Java-based programs are called?

Java applets


What is a period of time during which a legislature meets to conduct business?

A session of congress


A session of congress when both member of both houses meet together?

Joint session


The Java Script object name refers to the list containing the webpages the user has already visited in the current session?

The object that stores the web page URLs that a user has visited in the current session is the history object. The history object is read-only. You can't manipulate it, for obvious security reasons. However, you can use it to do things like create a "back" button in the page.


Differences between Java Applet and Java Beans?

Java applet is a program used to run java applications while beans is a compiler used to design java programs (IDE, GUI) :-) GilbertC