Session Management Using URL Rewriting in Servlet | URL Rewriting Session Tracking in Servlet

Let us learn in detail about Servlet Session Management using URL Rewriting. You can go with this technique URL Rewriting to manage the session. Before discussing this technique in detail let’s first understand what URL Rewriting means exactly in the further modules. You will get acquainted with Syntax, Advantages, Disadvantages, URL Rewriting for Session Tracking in Servlet Examples.

Also, See:

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. You can send textual information from one resource to another resource by utilizing a URL. In URL we can send the parameter name and value and this value we can get using the getParameter() method. In this technique, the session id will be added to the URL of the next resource or request.

Syntax of URL Rewriting:

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

Advantages of URL Rewriting

There are quite a few advantages that come with the URL Rewriting Tracking Mechanism in Servlet. They are in the below fashion

  1. You can avail this technique if the client disables the cookies in the browser.
  2. URL Writing supports all browsers.

Disadvantages of URL Rewriting

There are certain drawbacks of using the URL Rewriting Method and they are as such

  1. The Drawback with this is technique is it sends only textual information.
  2. It can be tedious.
  3. URL Rewriting works with links.

URL Rewriting Example

In this example, we will 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 the user profile otherwise it will redirect to the login page and give you a message wrong username and password. Let’s understand this with the example given below.

index.html file:

Session Management Using URL Rewriting in Servlet 1

UrlRewritingServlet1.java file:

Session Management Using URL Rewriting in Servlet 2

UrlRewritingServlet2.java file:

Session Management Using URL Rewriting in Servlet 3

Web.xml file:

Session Management Using URL Rewriting in Servlet 4

Session Management Using URL Rewriting in Servlet 5

Session Management Using URL Rewriting in Servlet 6

Session Management Using URL Rewriting in Servlet 7