How to get referrer of parent page?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajiv82
    New Member
    • Dec 2009
    • 4

    How to get referrer of parent page?

    I have a main page say Main.jsp which has a Iframe in it whose src is page1.jsp

    Page1.jsp has a form in it and we have a button on Main.jsp

    We submit form inside Ifame(page1.jsp ) using the button on main page with javascript.

    Once a form is submitted, we redirect it to some error page in case of error.
    Here we have a back button which should move us to Main.jsp.

    We are using referer for identifying the page from which error page is coming so that when we press back button, we will be redirect to correct page.

    But, whats happening is that when we are submitting form, url of Frame is passed as referer instead of Main.jsp.

    How can we get the Main.jsp in Referer?

    Please note for some security reason history.go(-1) doesn't work.
    Last edited by Frinavale; Dec 2 '09, 05:46 PM. Reason: Moved to Java from HTML.
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    In the jsp code of page1.jsp, see if the referrer (HTTP_REFERRER) is anyone other than Main.jsp, redirect it to Main.jsp.

    Comment

    • rajiv82
      New Member
      • Dec 2009
      • 4

      #3
      Thanks hsriat for your reply. How can I redirect HTTP_REFERRER to Main.jsp
      I used setHeader to set the Referer to Main.jsp, but IE again sets it to page1.jsp

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        You don't need to do anything to referrer, just find out who is the referrer to page1.jsp
        If the referrer is main.jsp, no need to do anything, but if the referrer is not main.jsp, redirect the client to the Main.jsp page.

        Follow this psudocode..

        if (getHeader("HTT P_REFERRER") != Main.jsp)
        setHeader("Loca tion: Main.jsp")

        This above code needs to be in the starting of page1.jsp
        I hope I made it clear this time.

        Comment

        • rajiv82
          New Member
          • Dec 2009
          • 4

          #5
          Thanks a lot man, it really worked

          Comment

          • rajiv82
            New Member
            • Dec 2009
            • 4

            #6
            One more issue with this:(

            Previously I hard coded my URL like setHeader("Loca tion", "http://server:host/a/abc/Main.jsp) and it worked all the time.

            But, I can't hard code the URL as it contains server/host/directory structure, etc..

            How can I get the URL of parent of IFrame and store it permanently to always pass that URL in setHeader ?

            I have checked in my Page1.jsp, first time doing getHeader("Refe rer") returns url for Main.jsp to which I want to redirect. But, when a submit button is clicked in frame, Referer is changed.

            say I have done like:
            setHeader("Loca tion", getHeader("Refe rer")) - Just not to hardcode my url, but it doesn't work.

            Please let me know is there any way I can save the Referer(URL) which is coming first (Main.jsp) time or I can get the Iframe parent in jsp, so that I can set header with that URL.

            I hope you understood the problem

            Comment

            • hsriat
              Recognized Expert Top Contributor
              • Jan 2008
              • 1653

              #7
              I could not understand what exactly the problem is. Try to provide a relative url in the location header rather than absolute.

              Eg. Instead of setHeader("Loca tion", "http://www.xxx.yyy/zzz.jsp"), try setHeader("Loca tion", "/zzz.jsp") depending upon what is the present location.

              And for comparing the referrer, make use of some algorithm/method to check if its matching, rather than to check if it is exactly equal with object.equals() method.

              Not the best solution, but I think it will work.

              Comment

              Working...