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:
- Session Management in Servlet Using HttpSession
- Session Tracking in Servlet and its Techniques
- Servlet interface and its methods explained with example
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¶mname2=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
- You can avail this technique if the client disables the cookies in the browser.
- URL Writing supports all browsers.
Disadvantages of URL Rewriting
There are certain drawbacks of using the URL Rewriting Method and they are as such
- The Drawback with this is technique is it sends only textual information.
- It can be tedious.
- 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:
UrlRewritingServlet1.java file:
UrlRewritingServlet2.java file:
Web.xml file: