Session Management Using URL Rewriting in Servlet - Javastudypoint

Sunday, October 14, 2018

Session Management Using URL Rewriting in Servlet

In this tutorial, we will learn another technique to manage the session. In the previous technique, we have learned session management using Hidden Form Field. Here we will learn third techniques URL Rewriting to manage the session. Before discussing this technique in details let's first understand about URL Rewriting.



What is meant by URL Rewriting?

URL Rewriting is another way to maintain session tracking.URL Rewriting technique can be used if the client has disabled the cookies in the browser. In URL Rewriting we can send textual information from one resource to another resource using URL. In URL we can send the parameter name and value and this value we can get using getParameter() method. In URL Rewriting technique session id will be added to the URL of the next resource or request.

Read: Session Management using Hidden Form Field


Syntax of URL Rewriting:  

url?paramname1=paramvalue1&paramname2=paramvalue2...

Advantages of URL Rewriting:

 1) URL Rewriting technique can be used if the client has disabled the cookies in the browser.
 2)  It works with all the browser.


Disadvantages of URL Rewriting:

1) In URL Rewriting we can send only textual information.
2)  URL Rewriting can be tedious.
3)  Only work with links.


URL Rewriting Example:

In this example, we are going to show you how to manage the session using URL Rewriting techniques. Here we have created a login page and validate the username and password. If the user enters the right credential it will show user profile otherwise it will redirect to login page and give you a message wrong username and password. Let's understand this with the example given below.




index.html file:
URL Rewriting in Servlet

UrlRewritingServlet1.java file:
URL Rewriting in Servlet



UrlRewritingServlet2.java file:
URL Rewriting in Servlet



Web.xml file:
URL Rewriting in Servlet




URL Rewriting in Servlet



URL Rewriting in Servlet





URL Rewriting in Servlet


You may also like:

What is Servlet API in Java?
Servlet Life Cycle with Example
How to get Form Data in Servlet?
How to create Hello World Servlet with Tomcat 7?

No comments:

Post a Comment