6 Replies Latest reply: Jul 5, 2011 10:34 AM by 778083 RSS

    showDocument(..): referer header is not set

    778083
      Hello everybody


      I've got an applet with a button. After clicking on it, the user is redirected to a JSP page (on same webserver) with following code in actionPerformed():

      getAppletContext().showDocument(new URL(getCodeBase() + "anotherPage.jsp"), "_self");


      In anotherPage.jsp I need the info from which URL the user is coming from (because same applet is embedded in different html pages).
      For this, I use the 'referer' header:

      *<% String backLink = request.getHeader("referer"); %>*


      This works fine with Firefox, but not with Internet Explorer.

      Is this a bug in IE or is there some browser specific code in the JRE which works not correct for all browsers?

      Has anyone an idea to get this working in IE?

      Thanks in advance
      Markus
        • 1. Re: showDocument(..): referer header is not set
          802711
          The referral header is optional [1] so not all browsers use it, in some cases it can be seen as a security issue and is often removed by third part security suites. The simplest way round this is to send the previous URL as a GET parameter e.g.
          getAppletContext().showDocument(
              new URL(getCodeBase() + "anotherPage.jsp?prevPage=home/login.jsp"), 
              "_self"
          );
          anotherPage.jsp
          <%
              String backLink = "First Page";
              if (request.getParameter("prevPage") != null) {
                   backLink = request.getParameter("prevPage");
              } 
          %>
          A more robust system using the user's session instead is described here:
          http://www.thatsjava.com/java-socket-programming/237068/

          [1] http://www.w3.org/Protocols/HTTP/HTRQ_Headers.html#z14
          • 2. Re: showDocument(..): referer header is not set
            778083
            Thanks for your suggestion, but unfortunately this works not for me. The problem is, that the same applet exists in several different html pages, so I can't hardcode the prevPage param.
            A possible solution would be to create dedicated applets for each html page, but this is inappropriate (99.999% of duplicated code, just a different url param).

            Hmm, seems there exists no solution :-(
            • 3. Re: showDocument(..): referer header is not set
              sabre150
              I may be missing something but each page that displays the Applet must have an <APPLET> tag so you can set the referral page as a parameter. For instance
                <applet codebase="..."
                   code="YourApplet.class" width=400 height=75>
                <param name="referral" value="some page">
                </applet>
              and pick this up in the Applet
              String referral = applet.getParameter("referral");
              • 4. Re: showDocument(..): referer header is not set
                793415
                sabre150 wrote:
                I may be missing something ..
                As might I, but..
                <applet codebase="..."
                     code="YourApplet.class" width=400 height=75>
                <param name="referral" value="some page">
                </applet>
                ..isn't the <tt>referral</tt> <tt>param</tt> equivalent to the applet's document base? The <tt>Applet</tt> class provides a convenient method to determine the document base.
                • 5. Re: showDocument(..): referer header is not set
                  sabre150
                  Andrew Thompson wrote:> > ..isn't the <tt>referral</tt> <tt>param</tt> equivalent to the applet's document base?  The <tt>Applet</tt> class provides a convenient method to determine the document base.Probably but it seemed to me that the OP wanted to go elsewhere than the document base. The OP need to provide a more detailed use-case and/or sequence diagram/statement.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
                  • 6. Re: showDocument(..): referer header is not set
                    778083
                    ah, great. so I can simply use getDocumentBase() in the applet code and append this value as a param to an url.

                    thanks for this simple workaround!