简易服务器

package test;

import java.io.IOException;
import java.net.InetSocketAddress;

import com.sun.net.httpserver.HttpServer;

public class HttspServer {

public static void main(String[] args) throws IOException {
    int port = 8080;
    HttpServer server =  
    System.out.println("server started at " + port);

// server.createContext("/", new RootHandler());
// server.createContext("/echoHeader", new EchoHeaderHandler());
// server.createContext("/echoGet", new EchoGetHandler());
server.createContext("/sb", new EchoPostHandler());
server.setExecutor(null);
server.start();

}

}

public class EchoPostHandler implements HttpHandler {
int port = 8080;

@Override
public void handle(HttpExchange he) throws IOException {
    // TODO Auto-generated method stub
    String response = "1";
    he.sendResponseHeaders(200, response.length());
    OutputStream os = he.getResponseBody();
    String s = "shh";
    os.write(response.getBytes());
    os.close();
}

}

你可能感兴趣的:(简易服务器)