• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URL rewriting

 
pratapsiva sivakumar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello can anyone explain URL rewriting with a code example for maintaining session.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Praveen Shabrish
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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=’/Example.do’ />”>Click here</a>

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

Final sample URL : (look at the jsessionid appended to the URL)
http://www.tester.com/Example.do;jsessionid=0CCB5C8DE517
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic