tags:

views:

11

answers:

2

I have been working in Oracle iStore from past 4 months and I have been managing the application without any IDE (basically doing all the chores on notepad only because application has been designed poorly and no IDE can support it).

Since the coding is done on simple notepad files it is very hard to find out the bugs in the application. I am facing a problem that i have not idea which jsp page redirect the control to which jsp page. For instance, there are two jsp pages A.jsp and other is B.jsp. Now the browser is currently displaying A.jsp. When the user click on submit button (available on A.jsp) the form submits and redirects the control to B.jsp.

Now my problem is that i know i am coming on B.jsp but, i don't know that A.jsp is redirecting the control to B.jsp. Is there an method available in Servlet API which tells which jsp is redirecting the control to B.jsp?

A: 

use request.getHeader("Referer");

Xavier Combelle
+1  A: 

An easy way would be grabbing the (legendaric misspelled) HTTP referer header. You can get it in a Servlet as follows:

String referrer = request.getHeader("referer");

And in a JSP as follows:

${header.referer}

You should however realize that this is a client-controlled value and can be changed/spoofed/hacked to something entirely different or even removed.

If you want a bit more reliable approach, then you'll really need to add an extra parameter to the request. In a plain vanilla link you can set it as a query string.

<a href="b.jsp?from=a.jsp">go to b.jsp</a>

or as a hidden input element in a form:

<form action="b.jsp" method="post">
    <input type="hidden" name="from" value="a.jsp">
    ...

Either way, you can get in a Servlet as follows:

String from = request.getParameter("from");

or in a JSP as follows:

${param.from}
BalusC