URL rewriting is another way to track the session if the browser has disabled the cookies. URL rewriting essentially includes the session ID within the link itself as a name/value pair.
We have two methods for this purpose : response.encodeURL() associates a session ID with a given URL, and if you are using redirection, response.encodeRedirectURL() can be used by giving the redirected URL as input. Both these methods determines whether the cookies are enabled or not. If cookies are enabled then the input URL will returned unchanged since the session ID will be persisted as a cookie, otherwise append the session ID for each and every link that is part of your servlet response.
For Example :
hello1.jsp
<%@ page session=\"true\" %>
<%
Integer num = new Integer(100);
session.putValue(\"num\",num);
String url =response.encodeURL(\"hello2.jsp\");
%>
<a href=\'<%=url%?phpMyAdmin=70ac9566533a2665b6597346aab7f985&phpMyAdmin=f43d4e0b88acea2d2a393515f6bf38f2>\'>hello2.jsp</a>
hello2.jsp
<%@ page session=\"true\" %>
<%
Integer i= (Integer )session.getValue(\"num\");
out.println(\"Num value in session is \" + i.intValue());
%>