File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes sessionId Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "sessionId" Watch "sessionId" New topic
Author

sessionId

Brijesh shah
Ranch Hand

Joined: Mar 16, 2007
Posts: 90
Hello;

I know how session gets created by using httpSession object through which we can get and set session attribute in our webapps...n in this if we want any session attributes id then we use session.getId().

Is this different from sessionId thing of encodeURL() method...

Hope you get my doubt..

Waiting for your reply.

Regards;
Brijesh Shah
-SCJP1.5
-SCWCD(preparing).
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Careful. Session attributes are what get retrieved by session.getAttribute - calling other things attributes will lead to confusion.

The session.getId() should return the Id of the session, also known as JSESSIONID. This value gets added to URLs when you encode them, like you asked.


A good workman is known by his tools.
Brijesh shah
Ranch Hand

Joined: Mar 16, 2007
Posts: 90
hello;

Thanks for replying marc.

I understood your point but i still confused, If i get the session id by session.getId(). The same thing can be done by encoding on url.

So my point is we can get the id through session.getId(), then why and what the use of encoding url.

--
Brijesh
James Mark
Ranch Hand

Joined: Jul 05, 2007
Posts: 115
jsessionid=JSESSIONID is true because sessionid is same for URL encoding


SCJP1.4(96%) SCWCD1.4(92%)
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Originally posted by Brijesh shah:
So my point is we can get the id through session.getId(), then why and what the use of encoding url.

Convenience.
Schandha Ravi
Ranch Hand

Joined: Oct 20, 2007
Posts: 167
Hi Mark,

I'm a beginner in Web component world and just started preparing for my exam. I have a small query here. Is that for "Convinience" or for routing back the sessionid to client via encoding URL, as the client may not be interested in accepting cookies.

Also, it is mentioned in Head First book that, Container woule embed a session object into a cookie and send it back to client through response. Good. But when there is a subsequent request from the client, Container verifies the cookie that came along with request. Now, my point is "Is the request coming from client application running from browser or the browser itself", because I haven't seen any code where any client application sending cookie along with its request.

An extension to the above question, assuming that browser would attach the cookie and send the http request to server, how can browser determine the exact cookie as we may have many cookies stored in our client machine through out the day browsing different sites. Please clarify me on these.

Thanks
Ravi


Thanks & Regards, SK
SCJP 5.0, DB2 - 800, DB2 - 803, SCDJWS (On the way)
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

An extension to the above question, assuming that browser would attach the cookie and send the http request to server, how can browser determine the exact cookie as we may have many cookies stored in our client machine through out the day browsing different sites. Please clarify me on these.

I'll start with this first because it's the easiest. When a browser stores cookies, it also stores the domain. So you can have multiple cookies -even of the same name- stored on a single machine if they are from different domains.

I'm a beginner in Web component world and just started preparing for my exam. I have a small query here. Is that for "Convinience" or for routing back the sessionid to client via encoding URL, as the client may not be interested in accepting cookies.

Also, it is mentioned in Head First book that, Container woule embed a session object into a cookie and send it back to client through response. Good. But when there is a subsequent request from the client, Container verifies the cookie that came along with request. Now, my point is "Is the request coming from client application running from browser or the browser itself", because I haven't seen any code where any client application sending cookie along with its request.

The browser sends all the cookies with every request for the given domain. If the browser has cookies disabled, then we have to rely on URL rewriting. The API HttpServletResponse methods are actually encodeURL and encodeRedirectURL but the process is really rewriting, as encoding really means something else entirely. You could try to rewrite the URLs yourself but letting the container do it is a ton easier. The absolute easiest way is to use the c:url tag everywhere you don't want a user to get disconnected from a session.
 
 
subject: sessionId
 
Similar Threads
Getting session info based on Session Id
How to know the sessionID is alive ?
How to ge know which users are using an app?
invalidate a session by using session id
Tomcat Returns Different Session Id