What Is URL Rewriting
As we know that session needs to be maintained because http is a stateless protocol.Due to which connection is lost or session is lost after every request response cycle between the client and the server.In order to maintain or track the session the server needs to get the additional information of the session id so that the session object pertaining to the client or server can be retrieved at the server side and the session can be managed.The session can be managed by either cookies,hidden parameter or URL rewriting.
URL Rewriting is used in the cases where client browser does not accept cookies.In such case the server does not get the session id thus it is unable to relate he session object with the client or user.In order to maintain the session some extra piece of code needs to be added so that even if the cookies are not accepted at the browser level still the session can be maintained.URL Rewriting is something to fall upon as a precautionary measure.The code to get session and URL Rewriting is demonstrated below :
request.getSession();
out.println("<a href = "\"+response.encodeURL()+""\>Click Here</a>");
Here the anchor tag is used for URL Rewriting.Since the extra measure is used to take care that if the client browser does not accept cookies the session id is attached to the URL so that the session can be maintained.In URL Rewriting the session id is passed as an extra information with the URL that means rewriting of the URL is done.URL Rewriting can also be done with redirection as below :
response.sendRedirect(response.encodeRedirectURL("URL-Pattern of the servlet"));
The first time the server tries with both cookies and URL Rewriting ,if it finds that the cookies are not coming it checks for session id as a part of URL Rewriting and finds that it has to fall upon URL Rewriting if the code has provisioned that.
Number of View :5909
Related posts:
- Basic Servlet Attributes Thread Safety Interview Questions Answers Explained
- Types Of Attributes In Servlet Servlet Scopes And Attributes Saving Data In A Servlet Attributes Interview Question
- Concept Of Session In J2EE Session Tracking In J2EE Session Management Seesion Concept Servlet Basics Servlet Guide Session Tracking
- How Container Does The Cookie Work in J2EE Define Cookie Cookies Explained Session In Servlet What Is Cookie How Apache Tomcat Handles Cookies Cookies Explained How Cookies Work Cookie Guide
- Life Cycle Of A Servlet Explained Handling Servlet Life-Cycle Events Servlet Life Cycle Servlet Interview Questions Java Servlet Programming
Tags: cookies, encodeRedirectURL(), encodeURL(), getSession(), j2ee, java, request, response, sendRedirect(), url rewriting
This entry was posted on Sunday, May 20th, 2012 at 2:28 am and is filed under Java, OPPS, software, Tech-Tips, Tips & Tricks. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.