title: Java HTTP server not working
body: <p>I am hosting a webpage from home. I made my own HTTP server using Java. This is an SSCCE:</p>
  
  <pre><code>if(command.startsWith("GET"))
  {
              //client is a socket on which I reply.
              PrintWriter pw = new PrintWriter(client.getOutputStream(), true);
      String commule = command.split(" ");
      if(commule[0].equals("GET"))
      {
          if(commule[1].contains("."))
          {
              File file = new File(GEQO_SERVER_ROOT + commule[1].substring(1).replaceAll("%20", " "));
              if(file.exists())
              {
                  OutputStream out = client.getOutputStream();
                  InputStream stream = new FileInputStream(file);
  
                  String response = new String();
                  response += "HTTP/1.1 200 OK\r\n";
                  response += "Date: Thu, 08 Aug 2013 08:49:37 GMT\r\n";
                  response += "Content-Type: text/html\r\n";
                  response += "Content-Length: " + file.length() + "\r\n";
                  response += "Connection: keep-alive\r\n";
                  response += "\r\n";
                  pw.write(response); //Assume I already initialized pw as a PrintWriter
                                      pw.flush();
                  copy(stream, out);
                  stream.close();
                  out.close();
              }
              else
              {
                  pw.write("&lt;html&gt;&lt;h1&gt;The request 404ed.&lt;/h1&gt;");
                  pw.write("&lt;body&gt;The requested URL &lt;b&gt;" + commule[1] + "&lt;/b&gt; could not be found on this server.&lt;/body&gt;&lt;/html&gt;");
                                      pw.flush();
              }
          }
          else
          {
              BufferedReader br = new BufferedReader(new FileReader(GEQO_SERVER_ROOT + commule[1].substring(1) + "main.html"));
              String sCurrentLine;
              while ((sCurrentLine = br.readLine()) != null) 
              {
                  pw.print(sCurrentLine);
              }
              br.close();
          }
      }
      else
      {
          pw.println("Unrecognized HTTP command.");
      }
  }
  </code></pre>
  
  <p>This is the main.html source :</p>
  
  <p><code>&lt;html&gt;</code><br>
  <code>&lt;title&gt;Geqo Server&lt;/title&gt;</code><br>
  <code>&lt;body&gt;Geqo server online and functioning!&lt;/body&gt;</code><br>
  <code>&lt;/html&gt;</code></p>
  
  <p>The issue is that when I try to access this page using Chrome, it displays correctly (At least when using 127.0.0.1). But when I tried accessing it on Firefox on 127.0.0.1, it works, but just gives me the html source. IE also only gives me the source. Can anyone tell me why Firefox and IE only show the source, instead of parsing it?</p>
  
  <p>I think this contains some clues (Firebug screenshot) : </p>
  
  <p><img src="https://i.stack.imgur.com/kBSa0.png" alt="Firebug screenshot"></p>
  
  <p>My source seems to be coming in a <code>&lt;pre&gt;</code> tag. I donno why, but isn't that sort of the problem? </p>
  
  <p>I port-forwarded. Here's the page guys : <code>http://110.172.170.83:17416/</code> (Sorry, Stackoverflow doesn't allows numerical links.)</p>
  
  <p>EDIT : I found the problem. But before I explain, thanks to <a href="https://stackoverflow.com/users/2149440/bart">Bart</a> for the SSCCE, which I used to compare with my code. This is the problem : The <code>if</code> statement on the eighth line <code>if(commule[1].contains("."))</code> causes the code to skip the most of the code here. In that respective <code>else</code> block, there is even no command to send the headers. Thanks to <a href="https://stackoverflow.com/users/116509/artbristol">artbristol</a> for pointing that out.</p>
  
  <p>Thanks in advance.</p>