java2db

URL rewriting in servlets ( Servlet session tracking )



URL rewriting is the alternative for cookies in servlet session tracking.
URL rewriting in servlets ( Servlet session tracking ) In some situations, the browser device does not accept cookies,in that case the URL rewriting is a solution to maintain session tracking.
URL rewriting in servlets ( Servlet session tracking ) URL rewriting involves encoding the session ID into the hyper-links on the Web pages that our servlet sends back to the browser.
URL rewriting in servlets ( Servlet session tracking ) When the user subsequently clicks these links, the Server extracts the ID from the URL address and finds the appropriate HttpSession when our servlet calls the getSession() method.

URL rewriting in servlets ( Servlet session tracking ) Example for servlet URL rewriting :

URL rewriting in servlets ( Servlet session tracking ) Directory Structure in eclipse IDE:

URL rewriting in servlets ( Servlet session tracking )

Source code :
URL rewriting in servlets ( Servlet session tracking ) index.jsp

URL rewriting in servlets ( Servlet session tracking ) URLRewriteServlet.java

URL rewriting in servlets ( Servlet session tracking ) ResultServlet.java

URL rewriting in servlets ( Servlet session tracking ) web.xml

URL rewriting in servlets ( Servlet session tracking )  Execution Result :

Enter the initial URL (In our example it is http://localhost:8080/URLrewritingApp/index.jsp) to load home page and enter the detail.

Click the submit button , the below response will come from the server with new URL ( Encoded url with session Id).Enter the details and click submit button.

The final result will come with all entered details.




Related Posts :
Kill or invalidate session using session id ( concurrent login )
Servlet Filter ( Request and Response filters in servlets ) example
Servlet Cookies ( Servlets session tracking with cookie )
Hidden form field in servlets ( Servlet session tracking )
Request attributes in servlet with an example ( Attribute scope )
Session attributes in servlet with example (Attribute scope)
ServletConext Attributes in servlet ( Attribute scope )
The sendRedirect (servlets are in different web applications)
   [will not be published]



^ <