IT程序员开发必备-各类资源下载清单,史上最全IT资源,个人收藏总结!
Web服务器:
import java.net.*;
import java.io.*;
public class Server
{
public static void main(String args[])throws Exception{
ServerSocket server = new ServerSocket(8888);
Socket sock = server.accept();
FileInputStream in = new FileInputStream("E:\\赛杰\\工程空间workspace\\jsp_方立勋\\ITSTAR版web服务器\\hello.html");
OutputStream out = sock.getOutputStream();
int len = 0;
byte[] buffer = new byte[1024];
while((len=in.read(buffer))>0){
out.write(buffer,0,len);
}
in.close();
out.close();
sock.close();
server.close();
}
}
hello.html文件:
<font color="red" font-size="50px">Hello word!</font>
(1)在cmd窗口运行Server.java文件(java Server)(程序处于等待状态,知道浏览器上访问8888端口,程序才会结束)
(2)在浏览器上访问:http://localhost:8888/
(3)此时cmd中程序已经结束运行,再次访问http://localhost:8888/,则无法访问: