Reputation: 6527
What are the different ways to track the session in servlet. Is it is possible by using hidden files ?
Upvotes: 0
Views: 2986
Reputation: 45
There are various session tracking mechanisms
Hidden Form Fields ->
In this case, we use hidden text-field for maintaining the state of a user. It is just programmer's trick to remember client information.
Upvotes: 0
Reputation:
Suppose a servlet that implements HTTP sessions receives HTTP requests from three different clients (browsers). For each client request, the servlet must be able to determine the HTTP session to which the client request pertains. Each client request belongs to just one of the three client sessions being tracked by the servlet. Currently, the product offers three ways to track sessions:
With cookies
With URL rewriting
With SSL information
Upvotes: 0
Reputation: 6050
Session can be maintained in flowing ways
The HttpSession
depend on the cookies. It uses cookies to store the session id in client system.
Upvotes: 0
Reputation: 449
The different ways to track session in servlet are:
Using the session API: a sample code for that is:
//store the username object in the session-scope
HttpSession session = request.getSession();
session.setAttribute("username",username);
To retrieve the session attribute,use the session.getAttribute()
Username username = (Username) session.getAttribute("username");
Using the cookies API: sample code:
String name = request.getParameter("username");
Cookie c = new Cookie("username",name);
response.addCookie(c);
It should be noted that a major disadvantage of using cookies for session management is that sometimes the client might have cookies turned off.
Using URL-Rewriting: The URL-rewriting strategy is not as transparrent as the cookie strategy. It could be implemented in a form as below:
//present the form
out.println("<form action='"+response.encodeURL("login.")+"'");
Hidden form field can also be used.
Upvotes: 2
Reputation: 13556
There are three ways
One of the ways is to use HttpSession
You can create session using
HttpSession session = request.getSession();
or you can use HttpSession session = request.getSession(true)
. Both statements mean that If there is associated session with this user, then return that one or create a new session. If false
is passed, then new session is not created.
Upvotes: 6
Reputation: 8473
These are the ways to tracking Session
1.With cookies
2.With URL rewriting
3.With SSL information
For more details click here
Upvotes: 0
Reputation: 13844
sessions can be maintained in the following ways
Upvotes: 3
Reputation: 121998
Yes,it is possible with hidden fields.
And there are other ways too
Upvotes: 1