I want to write a Servlet, which is called within a WWW-Page, and which
gets some info about the surfer, especially the referrer page he is from.

Just a servlet would be similar to the SnoopServet from Sun, but the
result (the info) should not be reported to the user (=surfer), it should be
written in a file, and the surfer should see the regular WWW Page (every page, in 
which this servlet is embedded, like in the sample HTML file below).
(The servlet is for getting info for statistical purpose)

So I am calling the servlet within a <img scr=...> HTML command, but ... and
this is my problem ... the referrer page, which is written to the file is
now the WWW page, where the servlet is embedded (and not the real referrer page)

Does anybody know what I must do to get the right results?

(Additional information: I am using Apache Webserver, JServ 1.0, JSDK 2.0, JDK 1.2.1)


Here is the Servlet Source:


import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.*;
import java.net.*;
import java.net.MalformedURLException;
import java.util.*;

public class BasicSnooperServlet extends HttpServlet{

  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    ServletOutputStream out = response.getOutputStream();
    response.setHeader("pragma", "no-cache");
    response.setContentType("image/gif");

    URL FilePath = new URL("http://localhost/stat.gif");
    URLConnection fp = FilePath.openConnection();
    InputStream ic =  fp.getInputStream();

    int data    =   ic.read();
    while (data !=-1) {
       out.write(data);
       data    =   ic.read();
    }

    try {
      RandomAccessFile raf =  new RandomAccessFile("/greetings2.log", "rw");
      raf.seek(raf.length());

      Enumeration e = request.getHeaderNames();
      if (e.hasMoreElements()) {
 while (e.hasMoreElements()) {
   String name = (String)e.nextElement();
          raf.writeBytes(name+request.getHeader(name));
 }
      }

    }
    catch (IOException e2) {
      System.out.println("Error opening file: " + e2);
    }

    out.close();
  }
}




And here the HTML Source:

<html>
<body>
This is the WWW-page, where the servlet is called<p>
<img src="/servlets/BasicSnooperServlet">

</body>
</html>


Thanks in advance for your help.

 Werner Moshammer
 [EMAIL PROTECTED]

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to