I think
you should be able to pull that information from the Referer header of the request, try:
request.getHeader("Referer");
It should give you the URL that you just came from (e.g. your servlet). Depending on what you are doing with it, you may have to parse the
string or check only the last part of it.
Hope this helps.