You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apps-dev@avalon.apache.org by Yann Secq <Ya...@lifl.fr> on 2002/06/21 13:58:44 UTC

HelloWorld example

Hi, still fighting to make it work with Mozilla (or any other
browser in fact).
A friend told me that I should try to consume first the request
issued from the browser, so I have added those lines :
(the strange condition is due to Mozilla who seems to 'keep alive'
the connection, and so in.ready() is always returning 'true) :

         final BufferedReader in = new BufferedReader(new 
InputStreamReader(socket.getInputStream()));
         try {
           String current = "";
           while(!current.startsWith("Connection")){
             current = in.readLine();
             getLogger().info(current);
           }
           in.close();
         } catch (IOException e) {
            getLogger().error("Exception while trying to read request 
"+e);
         }

Ant then I try to add HTTP headers (as I thought that the browser
would be happier with them :), but it didn't change a lot :

         try
         {
             //out.println( "HTTP/1.0 200 OK\r");
             //out.println( "Content-Type: text/html\r");
             out.println( "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 
Transitional//EN\">");
             out.println( "<html><body><b>" + m_greeting + "!</b><br> 
Requests so far = " +
                          ++c_counter + "<br>" );
             out.println( "you are " + remoteHost + " at " + remoteIP + 
"<br>" );
             out.println( "</body></html>" );
             out.flush();
             getLogger().info("ok, flushing done");
             socket.close();
         }

Now, all I have is an error message from the browser telling
me that 'The document contains no data' ...

I think, I'll stop working on this since I have not a lot of
knowledge on HTTP.

Cheers, yann.

-- 
  / Yann SECQ            Equipe SMAC           secq@lifl.fr \
| Multi-Agent Systems Modeling & Agent Oriented Programming |
  \ http://www.lifl.fr/SMAC        http://www.lifl.fr/~secq /


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>