Forum Stats

  • 3,826,581 Users
  • 2,260,667 Discussions
  • 7,897,008 Comments

Discussions

showDocument(..): referer header is not set

778083
778083 Member Posts: 5
edited Jul 5, 2011 11:34AM in Java Applet Development
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
Tagged:

Best Answer

  • 793415
    793415 Member Posts: 7,279 Bronze Badge
    edited Jul 5, 2011 8:50AM Answer ✓
    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.

Answers

  • 802711
    802711 Member Posts: 3
    edited Jun 28, 2011 8:37PM
    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
  • 778083
    778083 Member Posts: 5
    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 :-(
  • sabre150
    sabre150 Member Posts: 1,405
    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");
    sabre150
  • 793415
    793415 Member Posts: 7,279 Bronze Badge
    edited Jul 5, 2011 8:50AM Answer ✓
    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.
  • sabre150
    sabre150 Member Posts: 1,405
    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.
  • 778083
    778083 Member Posts: 5
    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!
This discussion has been closed.