Two Laptop Bag
The moose likes JSP and the fly likes URL rewriting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "URL rewriting" Watch "URL rewriting" New topic

URL rewriting

pratapsiva sivakumar

Joined: Nov 10, 2008
Posts: 18
Hello can anyone explain URL rewriting with a code example for maintaining session.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
URL rewriting is a fallback mechanism if the client rejects cookies which are the standard mechanism in force for session tracking.

You can encode a URL in your servlet using response.encodeURL() . Check the API dokumentation for more info on that.

As for JSPs, check c:url.

JDBCSupport - An easy to use, light-weight JDBC framework -
Praveen Shabrish

Joined: Sep 27, 2009
Posts: 3
Session plays an important role in most web applications. Since HTTP protocol is stateless, the Server identifies the user via the JSESSIONID cookie created at the user end. Most users don't disable cookies in their browser. But when a user has disabled cookies in his browser, URL rewriting is the only by which we can exchange session Id between client and the server.URL rewriting is simple.
In URL rewriting technique we can see that the jsessionid will be appended to the hyperlinks in the web page.

In JSP use the c:url tag.
<a href=”<c:url value=’/’ />”>Click here</a>

IN Servlets use the encodeUrl()
Use the encodeURL() function of response object.
out.println(“<a href=\”” + response.encodeURL(“/”) + “\”>click here</a>”);

Final sample URL : (look at the jsessionid appended to the URL);jsessionid=0CCB5C8DE517
I agree. Here's the link:
subject: URL rewriting
It's not a secret anymore!