I understood the question until you said you wanted to use Javascript to find what page requested your JSP. By the time you can use Javascript you've already generated the page and it's too late to find out. In a
servlet you would use, I believe,
to find the URL of the page that requested the servlet. I assume you can put that into a JSP as well.
Have you considered what you are going to do if somebody bookmarks the URL of your JSP and has the browser request it directly? You might want to consider Rajeev's suggestion.