呵呵,给你一个简单的 WEB 服务器例子,慢慢研究一下吧!功能: 将客户端(IE) 发过来的信息 , 显示出来.使用方法: 先执行这个 Java 程序, 然后在 IE 的地址栏输入 http://127.0.0.1:8000 就可以看到结果了. 至于 POST 你可以写一个 html 来测试.//HttpServer.javaimport java.net.*;
import java.io.*;public class HttpServer {
//端口号
int port = 8000;

public static final String CRLF = "\r\n";

public HttpServer() {
}

public HttpServer(int port) {
this.port = port;
}

public boolean start() {
boolean ok = false;
ServerSocket server = null;
Socket client = null;
StringBuffer sb = new StringBuffer(200);
try {
server = new ServerSocket(port);
System.out.println ("服务器创建成功,等待连接中...");

while(true) {
client = server.accept();
sb.setLength(0);
sb.append("------HTTP 访问的元数据如下------<br>");
InputStream is = client.getInputStream();
byte[] buf = null;
String line = null;
while(true) {
line = readLine(is);
if(line.length()==0) break;
//System.out.println(line);
sb.append(line);
sb.append("<br>");
if(line.indexOf("Content-Length:")>-1) {
int len = StringToPlusInt(line.substring(16));
buf = new byte[len];
}
}
String content = null;
if(buf != null) {
is.read(buf);
content = new String(buf,"UTF-8");
//System.out.println (content);
sb.append("<br>------HTTP 访问的实体数据如下------<br>");
sb.append(content);
sb.append("<br>");
}
//网页输出
OutputStreamWriter os = new OutputStreamWriter(client.getOutputStream(),"GBK");
PrintWriter out = new PrintWriter(os);
out.println("HTTP/1.1 200 OK");
out.println("content-type:text/html");
out.println("");
out.println("<html><head><title>成功</title></head><body><h2>截获成功,截获的数据如下:<br></h2>");
out.println(sb.toString());
out.println("</body></html>");
out.close();
is.close();
client.close();
}
} catch(IOException eio) {
System.out.println ("服务器创建失败!");
eio.printStackTrace();
}
return ok;
}

//读取一行字符.并返回 String 格式
String readLine(InputStream is) throws IOException {
int buf;
char c;
StringBuffer sb = new StringBuffer();

while(true) {
buf = is.read();
//\r 的ASCII码为 13
//\n 的ASCII码为 10
if(buf==13) {
is.read();//这里必须再读取一个字符,因为换行使用的 \r\n 
return sb.toString();
}else {
c = (char)buf;
sb.append(c);
}
}
    }
    //正数转换函数,返回数值小于0表示异常
int StringToPlusInt(String str) {
int rt = -1;
try {
rt = Integer.parseInt(str);
} catch (NumberFormatException nfe) {
System.out.println ("字符串转换为数字时出现异常.");
}
return rt;
}

public static void main(String args[]) {
HttpServer server = new HttpServer();
server.start();
}
}