Hello friends, I have a problem with this Code written for a server.It caters to the requests made by the browser . But the HTml page never loads .the browser says it is opening the default page..the progess bar comes to 50% and halts. Please help.(OF course, get a HTML file as default file) // a simple webserver import java.io.*; import java.util.*; import java.net.*; class Configuration { int port; String defaultfile; Configuration(){ port=80; defaultfile= "index.html"; // please get a html in your folder. } public int getPort(){ return port; } public String getDefaultFile(){ return defaultfile; } public void displayConfiguration(){ System.out.println("port: "+port); System.out.println("defaultfile: "+defaultfile); } } public class WebServer{ Configuration config; WebServer(){ config=new Configuration(); }
Hi Abhimanyu, I'm going to move this to the Java intermediate forum as it's not related to Certification study. ------------------ Jane Griscti Sun Certified Programmer for the Java� 2 Platform
Your response to the client has to start with an HTTP response line, like one of these: HTTP/1.1 200 OK HTTP/1.1 404 Not found then any HTTP headers: Content-type: text/html Content-length: whatever followed by one blank line, and then the data. If you're writing a web server (which is really not difficult, as you have discovered), you really should refer to the HTTP specification, RFC2616 at http://www.ietf.org/rfc/rfc2616.txt . It has all the answers.
Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072127686/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072124253/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
Abhimanyu dagla
Greenhorn
Joined: Jan 11, 2001
Posts: 20
posted
0
Thanks for the link , phil. The Server code has run, 'finally'. Abhimanyu