wood burning stoves*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "URL rewriting" Watch "URL rewriting" New topic
Author

URL rewriting

pratapsiva sivakumar
Greenhorn

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
Greenhorn

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=’/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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: URL rewriting
 
Similar Threads
redirecting the request to URL
URL rewriting ?
URL same
JSP/form/servlet - session persistence ?
Know technique for dynamic URL change