How to Track sessions in Mobile Phones while using Tomcat?

By sreedharan

These days mobile platform is being used for developing web applications. One of the important aspects of web applications is Session management. How can we maintain sessions in mobile phones?

Web sessions can be tracked either by cookies or Session ID’s. A web application can choose to use either of these methods. In mobile phones, for example, it is wise to use Session id. So how do we make a web application intelligent enough to maintain the session through either of these methods. The method suggested here is for the Tomcat.

The easiest way to do this is to encode all the URL’s using
response.encodeURL and response.encodeRedirectURL methods.

The first method encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. For example, if the browser supports cookies, or session tracking is turned off, URL encoding is unnecessary.

The second method is useful when requests are forwarded from one page to other.

For robust session tracking, all URLs emitted by a servlet should be run through the relevant method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.

Leave a Reply