How to get previous page URL from request using a servlet

How do I get the previous page URL from request using a servlet. For example, I’m from the index.html and I submitted a form from index, how do I get the index.html URL and use it in a servlet?

request.getRequestURL()

getRequestURL doesn’t work since it only returns the URL of the servlet.

Answer

Write in your Servlet the following code

String url = request.getHeader(“referer”);

This worked in my case.Hope it works for you as well

Leave a Reply

Your email address will not be published. Required fields are marked *