Servlet URL Rewriting

In this tutorial you will learn about the Servlet URL Rewriting and its application with practical example.

Servlet URL Rewriting

Using the url rewriting we can append parameter in url and can send our data to next servlet. We send the parameter in key-value pair. It works even cookie is disabled but it works only with links.

Table Of Contents

The format will be like below code:

here name is key and w3adda.com is value.

Example:-

Let’s understand it by an simple example.

index.html

This will be our welcome file. Check below code.

First.java

From this servlet class we will append our parameter in url. Check below code.

Second.java

Here we will get parameter of given url. Check below code.

Output:-

The below images will show output of this code.

Screen 1:-

This is our index.html file output.

image001

Screen 2:-

Below image is our First.java file output.

image003

Screen 3:-

In the Second servlet file we will get this parameter by the request.getParameter() method. Check below image.

image005

 

In this tutorial we have learn about the Servlet URL Rewriting and its application with practical example. I hope you will like this tutorial.